![]() |
UtilsLite
Utilities for C++ programming
|
Implement some operationn on quaternion. More...
#include <Quaternion.hxx>
Public Types | |
using | real_type = T |
Public Member Functions | |
Quaternion () | |
Quaternion (real_type A, real_type B, real_type C, real_type D) | |
void | setup (real_type A, real_type B, real_type C, real_type D) |
void | print (ostream_type &os) const |
real_type | operator[] (int i) const |
void | conj () |
void | invert () |
real_type | norm () const |
void | rotate (real_type const v[3], real_type w[3]) const |
real_type | to_axis (real_type axis[3]) const |
void | to_matrix (real_type mat[3][3]) const |
Implement some operationn on quaternion.
Quaternion Class
Represents a quaternion, which is a mathematical entity that extends complex numbers. A quaternion is defined as a quadruplet \( (A, B, C, D) \) of real numbers, often represented as:
\[ Q = A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \]
Quaternions are widely used in 3D computer graphics and robotics for representing rotations and orientations due to their efficiency and ability to avoid gimbal lock.
Reference:
using Utils::Quaternion< T >::real_type = T |
Type definition for the real number type of the quaternion.
|
inline |
Default constructor that initializes a null quaternion.
|
inline |
Constructs a quaternion with specified components.
A | The scalar part of the quaternion. |
B | The coefficient for \( \mathbf{i} \). |
C | The coefficient for \( \mathbf{j} \). |
D | The coefficient for \( \mathbf{k} \). |
|
inline |
Conjugates the quaternion:
\[ Q = A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \]
The conjugate of \( Q \) is given by:
\[ \overline{Q} = A - B \mathbf{i} - C \mathbf{j} - D \mathbf{k} \]
|
inline |
Inverts the quaternion:
\[ Q = A + B \mathbf{i} + C \mathbf{j} + D \mathbf{k} \]
The inverse of \( Q \) is calculated as:
\[ Q^{-1} = \dfrac{ A - B \mathbf{i} - C \mathbf{j} - D \mathbf{k}} { A^2 + B^2 + C^2 + D^2 } \]
|
inline |
Computes the norm of the quaternion.
The norm of \( Q \) is defined as:
\[ \text{norm}(Q) = \sqrt{A^2 + B^2 + C^2 + D^2} \]
|
inline |
Accesses the \(i\)-th component of the quaternion.
i | Index of the quaternion component (0 for A, 1 for B, etc.). |
|
inline |
Prints the quaternion to the specified output stream.
os | The output stream where the quaternion will be printed. |
|
inline |
Applies a quaternion rotation to a 3D vector.
If \( Q \) is a unit quaternion representing a rotation of ANGLE radians about the vector AXIS, the result \( W \) of the rotation on the vector \( V \) can be computed as:
\( W = Q * V * \overline{Q} \)
v | The input vector to be rotated. |
w | The output vector that will hold the result. |
|
inline |
Sets the components of the quaternion to the specified values.
A | The scalar part of the quaternion. |
B | The coefficient for \( \mathbf{i} \). |
C | The coefficient for \( \mathbf{j} \). |
D | The coefficient for \( \mathbf{k} \). |
|
inline |
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.
axis | An array that will be populated with the axis of rotation. |
|
inline |
Converts the quaternion to a 3x3 rotation matrix.
mat | A 3x3 array that will hold the resulting rotation matrix. |