zmath.quaternion
A Quaternion it's used to store a space orientation / rotation, and makes easy to interpolate rotations, at same time that avoid grimbal locks that have using Euler angles
-
Declaration
alias
Qua_f
= Quaternion!float.Quaternion;Alias of a Quaternion with floats
-
Declaration
alias
Qua_d
= Quaternion!double.Quaternion;Alias of a Quaternion with doubles
-
Declaration
alias
Qua_r
= Quaternion!real.Quaternion;Alias of a Quaternion with reals
-
Declaration
struct
Quaternion
(T = floatt) if (__traits(isFloating, T));Quaternion
over a FloatPoint type,-
Declaration
static enum size_t
dim
;Quaternion Dimension
-
Declaration
T
i
;i
complex component -
Declaration
T
j
;j
complex component -
Declaration
T
k
;k
complex component -
Declaration
T
w
;w
real component -
Declaration
T
x
;alias of i component
-
Declaration
T
y
;alias of j component
-
Declaration
T
z
;alias of k component
-
Declaration
this(in T
i
, in Tj
, in Tk
, in Tw
);Build a new Quaternion from a set of initial values
Parameters
T
i
i
imaginary componentT
j
j
imaginary componentT
k
k
imaginary componentT
w
i
real component -
Declaration
this(in T[]
xs
);Build a new Quaternion from a array If no there values for j, and k, will be set to 0. w is set to 1
Parameters
T[]
xs
Array with coords
-
Declaration
pure @nogc this(in Vector!(T, 3)
vec
);Build a new Quaternion from a 3D Vector w will be set to 1
Parameters
Vector!(T, 3)
vec
Vector 3d
-
Declaration
pure @nogc this(in Vector!(T, 4)
vec
);Build a new Quaternion from a 4D Vector
Parameters
Vector!(T, 4)
vec
Vector 4d
-
Declaration
@nogc this(U)(Vector!(T, 3)
v
, Uangle
) if (is(U : real));Creates a Quaternion from a 3d Vector and
angle
Parameters
Vector!(T, 3)
v
Rotation axis
U
angle
Rotation
angle
in radiansReturn Value
Quaternion that represents a rotation
-
Declaration
@nogc this(U)(U
roll
, Upitch
, Uyaw
) if (__traits(isFloating, U));Creates a new Quaternion from Euler angles Params :
roll
= Rotation around X axis in radians (aka bank)pitch
= Rotation around Y axis in radians (aka attitude)yaw
= Rotation around Z axis in radians (aka heading)Return Value
Quaternion that represents a rotation
-
Declaration
const pure @nogc T
opIndex
(size_ti
);Returns
i
coord of this vector -
Declaration
@nogc void
opIndexAssign
(Tc
, size_ti
);Assigns a value to a coord
-
Declaration
const pure @nogc @property T
length
();Returns the actual
length
of this quaternion -
Declaration
const pure @nogc @property T
sq_length
();Returns the actual squared length of this quaternion
-
Declaration
const pure @nogc bool
opEquals
()(auto ref const Quaternionrhs
);Define Equality
-
Declaration
const pure @nogc bool
approxEqual
()(auto ref const Quaternionrhs
, TmaxRelDiff
= 0.01, TmaxAbsDiff
= 1e-05);Approximated equality with controlable precision
-
Declaration
const pure @nogc Quaternion
opUnary
(string op)() if (op == "+" || op == "-");Define unary operators + and -
-
Declaration
const pure @nogc Quaternion
opBinary
(string op)(auto ref const Quaternionrhs
) if (op == "+" || op == "-");Define binary operator + and -
-
Declaration
const pure @nogc Quaternion
opBinary
(string op)(in Trhs
) if (op == "*");Define Scalar multiplication
-
Declaration
const pure @nogc Quaternion
opBinary
(string op)(auto ref const Quaternionrhs
) if (op == "*");Defines Hamilton product for Quaternions
Parameters
Quaternion
rhs
Quaternion at rigth of operation
Return: Quaternion result of hamilton product of this and
rhs
(thisrhs
) -
Declaration
const pure @nogc Quaternion
conj
();Obtain conjugate of a Quaternion
-
Declaration
const pure @nogc @property bool
isUnit
();It's a unitary Quaternion (length == 1)
-
Declaration
pure @nogc void
normalize
();Normalize this Quaternion
-
Declaration
const pure V
rotate
(V)(auto ref const Vv
) if (isVector!V && (V.dim >= 3));Apply a 3d rotation Quaternion over a 3d/4d Vector
-
Declaration
const pure @nogc Vector!(T, 3)
toAxisAngle
(out Tangle
);Calc the Axis and
angle
of rotation of this QuaternionParameters
T
angle
Set to
angle
of rotationReturn Value
Axis of rotation vector
-
Declaration
const pure @nogc Vector!(T, 3)
toEuler
();Returns a Vector with euler's angles
Return Value
Vector with Euler angles of rotation in radians
TODO: Improve using code from here to avoid requiring pre-normalize the quaternion http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
-
Declaration
const pure @nogc Tout
opCast
(Tout)() if (isQuaternion!Tout);Casting for convert between Quaternions
-
Declaration
const pure @nogc Tout
opCast
(Tout)() if (isMatrix!Tout && (Tout.dim >= 3));Casting to rotation Matrix
-
Declaration
string
toString
();Returns a string representation of this Quaternion
-
-
Declaration
immutable bool
isQuaternion
(T);Say if a thing it's a Quaternion