Template Class Quaternion

Class Documentation

template<typename T>
class Quaternion

Quaternion class.

A quaternion is a quadruplet (A,B,C,D) of real numbers, which may be written as /c Q = A + Bi + Cj + Dk.

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 real_type operator[](int i)

Return i-th coordinate of the quaternion.

inline void conj()

Conjugates a quaternion \( Q = A + Bi + Cj + Dk \). The conjugate of \( Q \) is \( \overline{Q} = A - Bi - Cj - Dk \).

inline void invert()

Invert a quaternion \( Q = A + Bi + Cj + Dk \). The inverse of of \( Q \) is \( Q^{-1} = \frac{A - Bi - Cj - Dk}{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 toAxis(real_type axis[3]) const

Converts a rotation from quaternion to axis format in 3D.

A rotation quaternion Q has the form:

Q = A + Bi + Cj + Dk

where A, B, C and D are real numbers, and i, j, and k are to be regarded as symbolic constant basis vectors, similar to the role of the “i” 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.

inline void toMatrix(real_type mat[3][3]) const

Converts a rotation from quaternion to rotation matrix.

Reference:

James Foley, Andries van Dam, Steven Feiner, John Hughes, Computer Graphics, Principles and Practice, Second Edition, Addison Wesley, 1990.

Public Members

T real_type

type quaternion of coordinate