Template Class Quaternion¶
Defined in File Quaternion.hxx
Class Documentation¶
-
template<typename T>
class Utils::Quaternion¶
-
Quaternion class
A quaternion is a quadruplet (A,B,C,D) of real numbers, which may be written as
\[ Q = A + B \mathbf{i} + C\mathbf{j} + D\mathbf{k} \]Reference:
| James Foley, Andries van Dam, Steven Feiner, John Hughes, | Computer Graphics, Principles and Practice, Second Edition, | Addison Wesley, 1990.
Public Functions
-
inline Quaternion()¶
-
Build null quaternion.
-
inline Quaternion(real_type A, real_type B, real_type C, real_type D)¶
-
Build quaternion \( A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \).
-
inline void setup(real_type A, real_type B, real_type C, real_type D)¶
-
Build quaternion \( A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \).
-
inline void print(ostream &os) const¶
-
Print a quaternion to stream.
-
inline void conj()¶
-
Conjugates a quaternion
\[ Q = A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \]The conjugate of \( Q \) is
\[ \overline{Q} = A - B \mathbf{i} - C \mathbf{j} - D \mathbf{k} \]
-
inline void invert()¶
-
Invert a quaternion \( Q = A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \). The inverse of of \( Q \) is
\[ Q^{-1} = \dfrac{ A - B \mathbf{i} - C \mathbf{j} - D \mathbf{k}} { A^2 + B^2 + C^2 + D^2 } \]
-
inline real_type norm() const¶
-
Computes the norm of a quaternion. The norm of \( Q \) is \( \sqrt{A^2+B^2+C^2+D^2} \).
-
inline void rotate(real_type const v[3], real_type w[3]) const¶
-
Applies a quaternion rotation to a vector in 3D.
If \( Q \) is a unit quaternion that encodes a rotation of ANGLE radians about the vector AXIS, then for an arbitrary real vector \( V \), the result \( W \) of the rotation on \( V \) can be written as:
\( W = Q * V * Conj(Q) \)
-
inline real_type to_axis(real_type axis[3]) const¶
-
Converts a rotation from quaternion to axis format in 3D.
A rotation quaternion Q has the form:
\[ Q = A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \]where A, B, C and D are real numbers, and \( \mathbf{i} \), \( \mathbf{j} \), and \( \mathbf{k} \) are to be regarded as symbolic constant basis vectors, similar to the role of the “\f$ \mathbf{i} \f$” in the representation of imaginary numbers.
A is the cosine of half of the angle of rotation. (B,C,D) is a vector pointing in the direction of the axis of rotation. Rotation multiplication and inversion can be carried out using this format and the usual rules for quaternion multiplication and inversion.