Quaternion class.
Quaternion class. If you're not familiar with quaternions, their key properties are:Quaternions can be manually initialized or they can be typecast from matrix or tmatrix objects. A handy trick for computing a quaternion representing a rotation of 'a' about an axis 'axis' is:
- They're basically the 4-dimensional equivalent of complex numbers
- They consist of a scalar component 'r' and three vector components 'i', 'j', and 'k'.
- They're very handy for representing orientations (or, equivalently, rotations)
- Quaternions should be normalized (i.e. r*r + i*i + j*j + k*k = 1) if you want them to represent rotations correctly.
quaternion q(cos(a/2), sin(a/2)*axis);To rotate a triple 't' by a quaternion 'q', the syntax is
tRotated = q*t*(~q);where ~ is the complement operator for quaternions. To rotate a triple 't' by the inverse of a quaternion 'q', the syntax istUnrotated = (~q)*t*q;Note that it's a good idea to include the parentheses to ensure that the complement is computed correctly.
Alphabetic index HTML hierarchy of classes or Java