|
Core 1.0
|
Quaternions. More...
#include <quaternion.h>
Public Member Functions | |
| Quaternion () noexcept | |
| Empty. | |
| Quaternion (const double &, const double &, const double &, const double &) noexcept | |
| Create a quaternion. | |
| Quaternion (const Vector &, const double &) | |
| Create a quaternion from an axis vector and a rotation angle. | |
| Quaternion (const Vector &, const Vector &) | |
| Create a unit quaternion representing the shortest rotation from vector a to vector b. | |
| Quaternion (const Matrix &) | |
| Create a quaternion from a rotation matrix. | |
| Matrix | RotationMatrix () const |
| Transforms a quaternion into a rotation matrix. | |
| void | AngleAxis (double &, Vector &) const |
| Transform a quaternion into an rotation defined by its axis and the angle of rotation angle. | |
| double & | operator[] (int) noexcept |
| Overloaded. | |
| constexpr double | operator[] (int) const noexcept |
| Returns the i-th coefficient of a quaternion. | |
| Quaternion | operator+ (const Quaternion &) const noexcept |
| Overloaded. | |
| Quaternion | operator- (const Quaternion &) const noexcept |
| Overloaded. | |
| Quaternion | operator* (const Quaternion &) const noexcept |
| Multiplication of two quaternion. | |
| Quaternion | operator* (const double &) const noexcept |
| Multiply a quaternion by a double value. | |
| Quaternion | operator- () const noexcept |
| Overloaded. | |
| Quaternion | Inverse () const noexcept |
| Compute the inverse of a quaternion. | |
| Quaternion | Conjugate () const noexcept |
| Computes the conjugate of a quaternion. | |
| Quaternion | Exp () const |
| Compute the exponential of a quaternion. | |
| Quaternion | Log () const |
| Computes the logarithm of a quaternion. | |
| Vector | operator* (const Vector &) const noexcept |
| Rotate a vector by this unit quaternion using the sandwich formula. | |
Static Public Member Functions | |
| static Quaternion | Slerp (const double &, const Quaternion &, const Quaternion &) |
| Perform spherical linear interpolation (slerp) between two unit quaternions. | |
| static Quaternion | FromAngles (const double &, const double &, const double &) |
| Create a quaternion from Euler rotation angles. | |
Static Public Attributes | |
| static const Quaternion | Null |
| Null quaternion. | |
| static const Quaternion | Identity |
| Identity. | |
Protected Attributes | |
| double | w = 1.0 |
| Quaternion components. | |
Static Protected Attributes | |
| static const double | Epsilon = 1e-03 |
| Cutoff value for sine function whenever the angle gets near zero. | |
Friends | |
| Quaternion | operator* (const double &c, const Quaternion &q) |
| Left multiply a quaternion by a double value. | |
| double | SquaredNorm (const Quaternion &q) |
| Squared length of a quaternion. | |
| double | Norm (const Quaternion &q) |
| Euclidean length of a quaternion. | |
| std::ostream & | operator<< (std::ostream &s, const Quaternion &quaternion) |
| Overloaded. | |
Quaternions.
|
inlineexplicitnoexcept |
Create a quaternion.
| w | Angular parameter. |
| x,y,z | Axis coordinates. |
|
explicit |
Create a quaternion from an axis vector and a rotation angle.
Axis should be unit length.
| axis | Normalized axis. |
| a | Angle. |
Create a unit quaternion representing the shortest rotation from vector a to vector b.
Both input vectors must be unit-length. The quaternion satisfies: \( q = \cos(\theta/2) + \sin(\theta/2)\,\hat{n} \) where \( \theta = \arccos(a \cdot b) \) and \( \hat{n} = (a \times b)/\|a \times b\| \).
Special cases:
| a,b | Unit vectors. |
|
explicit |
Create a quaternion from a rotation matrix.
The algorithm can be found in Ken Shoemake's article in 1987 Siggraph course notes Quaternion Calculus and Fast Animation. Coefficients are accessed with Matrix::operator()(int, int), i.e., R(i, j) is the coefficient at row i and column j, so that the quaternion of Matrix::Rotation(u, a) is the quaternion Quaternion(u, a), up to the sign.
| R | Rotation matrix. |
| void Quaternion::AngleAxis | ( | double & | angle, |
| Vector & | axis ) const |
Transform a quaternion into an rotation defined by its axis and the angle of rotation angle.
The quaternion representing the rotation is : q=cos(a/2)+sin(a/2)*(x*i+y*j+z*k).
| angle | The angle. |
| axis | Vector axis. |
| Quaternion Quaternion::Exp | ( | ) | const |
Compute the exponential of a quaternion.
If q=a*(x,y,z) where (x,y,z) is unit length, then exp(q)=cos(a)+sin(a)*(x,y,z). If sin(a) is near zero, use exp(a)=cos(a)+a*(x,y,z).
|
static |
Create a quaternion from Euler rotation angles.
Using this function is simpler than calling the constructor from a rotation matrix.
| a,b,c | Rotation angles around x, y and z axes (should be in radian). |
|
noexcept |
Compute the inverse of a quaternion.
This should be applied to non-zero quaternions only. If quaternion happens to be null, then the function return also null wich is an invalid result that flags the error.
| Quaternion Quaternion::Log | ( | ) | const |
Computes the logarithm of a quaternion.
If quaternion is of unit length, then q=cos(a)+sin(a).v, then log(q)=a.v.
|
inlinenoexcept |
Multiply a quaternion by a double value.
| c | Real. |
|
noexcept |
Multiplication of two quaternion.
Note that multiplication is not generally commutative.
Rotate a vector by this unit quaternion using the sandwich formula.
Uses the direct formula \( p' = p + 2w\,(q \times p) + 2\,(q \times (q \times p)) \) where \( q = (x,y,z) \) is the vector part and \( w \) is the scalar part. This avoids constructing the full 3×3 rotation matrix (which would cost 9 multiplications and 9 additions via RotationMatrix(), plus a matrix–vector multiply), and instead uses two cross-products and two scalar–vector multiplications — roughly half the floating-point operations.
| p | Vector to rotate. |
|
inlineconstexprnoexcept |
Returns the i-th coefficient of a quaternion.
Terms are x, y, and z if index is in [0,2], and w otherwise.
| Matrix Quaternion::RotationMatrix | ( | ) | const |
Transforms a quaternion into a rotation matrix.
Coefficients are given column by column, as expected by the constructor of Matrix, so that the matrix is the same as the one created by Matrix::Rotation(), and that q.RotationMatrix() * p is equal to q * p.
|
static |
Perform spherical linear interpolation (slerp) between two unit quaternions.
Interpolates along the shortest arc on the unit quaternion sphere. Negates q when the dot product is negative to always take the shorter arc. When the rotations are very close, the normalized linear interpolation is used, which avoids the division by the sine of the angle and differs from the spherical interpolation by a term of the order of the cube of the angle.
| t | Interpolating value in [0,1]: 0 returns p, 1 returns q. |
| p,q | Unit quaternions to interpolate. |
|
friend |
Euclidean length of a quaternion.
| q | Quaternion. |
|
friend |
Left multiply a quaternion by a double value.
| c | Real. |
| q | Quaternion. |
|
friend |
Overloaded.
| s | Stream. |
| quaternion | The quaternion. |
|
friend |
Squared length of a quaternion.
| q | Quaternion. |