#include <quaternion.h>
Quaternions extend the concept of rotation in three dimensions to rotation in four dimensions. This avoids the problem of "gimbal-lock" and allows for the implementation of smooth and continuous rotation. In effect, they may be considered to add an additional rotation angle to spherical coordinates ie. Longitude, Latitude and Rotation angles. A Quaternion is defined using four floating point values |v.x v.y v.z w|. These are calculated from the combination of the three coordinates of the rotation axis and the rotation angle. Because the rotation axis is specified as a unit direction vector, it may be calculated through vector mathematics or from spherical coordinates ie. (longitude/latitude). Quaternions offer another advantage in that they be interpolated - this allows for smooth and predictable rotation effects.
Static Public Member Functions | |
static ValueType | GetDot (const QuaternionType &q1, const QuaternionType &q2) |
static Result< QuaternionType > | GetLerp (const QuaternionType &q1, const QuaternionType &q2, const ValueType t) |
static Result< QuaternionType > | GetSlerp (const QuaternionType &q1, const QuaternionType &q2, const ValueType t) |
static Result< QuaternionType > | GetSquad (const QuaternionType &qi, const QuaternionType &qi_p1, const QuaternionType &si, const QuaternionType &si_p1, const ValueType t) |
static Result< QuaternionType > | GetInnerQuaternion (const QuaternionType &qi_m1, const QuaternionType &qi, const QuaternionType &qi_p1) |
static Result< QuaternionType > | GetSpline (const QuaternionType &qi_m1, const QuaternionType &qi, const QuaternionType &qi_p1, const QuaternionType &qi_p2, const ValueType t) |
static Result< void > | DescribeIO (const DataSerializeInterface &stream) |
Public Attributes | |
VectorType | v |
ValueType | w |
Private Types | |
using | VectorType = Vec3< ValueType > |
using | MatrixType = SqrMat3< Vec3< ValueType > > |
using | QuaternionType = Quaternion< ValueType > |
Private Member Functions | |
ValueType | MyCopysign (const ValueType &x, const ValueType &y) const |
Friends | |
QuaternionType | operator* (const ValueType s, const QuaternionType &q) |
|
private |
|
private |
|
private |
Creates a quaternion initialized with default values (all components 0.0).
Quaternion | ( | const VectorType & | v, |
const ValueType | w | ||
) |
Creates a quaternion and initialize it with given quaternion values.
Quaternion | ( | const ValueType | x, |
const ValueType | y, | ||
const ValueType | z, | ||
const ValueType | w | ||
) |
Creates a quaternion and initialize it with given quaternion values.
|
private |
const Quaternion< ValueType > & operator+= | ( | const QuaternionType & | v | ) |
Adds the components of two quaternions.
const Quaternion< ValueType > & operator-= | ( | const QuaternionType & | v | ) |
Subtract the components of two quaternions.
const Quaternion< ValueType > & operator*= | ( | const QuaternionType & | v | ) |
Concatenate two quaternion operations.
Quaternion< ValueType > operator+ | ( | const QuaternionType & | v | ) | const |
Adds the components of two quaternions.
Quaternion< ValueType > operator- | ( | const QuaternionType & | v | ) | const |
Subtracts the components of two quaternions.
Quaternion< ValueType > operator* | ( | const QuaternionType & | v | ) | const |
Concatenates two quaternion operations.
Quaternion< ValueType > operator* | ( | const ValueType | s | ) | const |
Scales the components of a quaternion.
void SetMatrix | ( | const MatrixType & | m | ) |
Converts a rotation matrix into a quaternion.
[in] | m | Rotation matrix (does not need to be normalized). |
void SetRotation | ( | const VectorType & | rotation | ) |
Converts a rotation of order X -> Y -> Z into a quaternion.
[in] | rotation | Rotation angle vector in radians. |
void SetAxisRotation | ( | const VectorType & | axis, |
const ValueType | rotation | ||
) |
Converts an axis and angle to a quaternion.
[in] | axis | Axis (does not need to be normalized). |
[in] | rotation | Rotation angle in radians. |
auto GetMatrix |
Derives a rotation matrix from the quaternion.
Result< void > GetAxisRotation | ( | VectorType & | axis, |
ValueType & | angle | ||
) | const |
Calculate axis and rotation angle from quaternion.
[out] | axis | Axis vector. |
[out] | angle | Angle value in radians. |
ValueType GetSquaredLength |
Calculates the squared magntitude/length/norm of a quaternion.
ValueType GetLength |
Calculates the magntitude/length/norm of a quaternion.
Result< Quaternion< ValueType > > GetNormalized |
Calculates the normalized quaternion.
Result< Quaternion< ValueType > > GetInverse |
Calculates the inverse of a quaternion.
Quaternion< ValueType > GetConjugate |
Calculates the conjugate of a quaternion.
Result< Quaternion< ValueType > > GetLog |
Calculates the logarithm of a quaternion.
Result< Quaternion< ValueType > > GetExp |
Calculates the exponential of a quaternion.
Result< Quaternion< ValueType > > GetPow | ( | const ValueType & | t | ) | const |
Calculates the quaternion power q^t.
[in] | t | Exponent. |
|
static |
Calculates the dot product of two quaternions.
|
static |
Interpolates two quaternions linearly with blend parameter t.
[in] | q1 | First quaternion. |
[in] | q2 | Second quaternion. |
[in] | t | Blend parameter [0.0, 1.0.] |
|
static |
Interpolates two quaternions spherical linearly with blend parameter t.
[in] | q1 | First quaternion. |
[in] | q2 | Second quaternion. |
[in] | t | Blend parameter [0.0, 1.0.] |
|
static |
Spherical quadrangle interpolation of a sequence of quaternions qi and qi+1 with blend parameter t Additionally you have to specify the innner quaternions si and si+1.
[in] | qi | Main quaternion at index i. |
[in] | qi_p1 | Main quaternion at index i+1 |
[in] | si | Inner quaterniona at index i. |
[in] | si_p1 | Inner quaternion at index i+1 |
[in] | t | Blend parameter [0.0, 1.0.] |
|
static |
Computer the inner quaternion from the series of quaternions qi-1, qi and qi+1
[in] | qi_m1 | Quaternion at index i-1 |
[in] | qi | Quaternion at index i. |
[in] | qi_p1 | Quaternion at index i+1 |
|
static |
Interpolates two quaternions qi and qi+1 smoothly using spherical spline interpolation with parameter t. qi-1 and qi+2 are used to provide C1 continuity at the borders.
[in] | qi_m1 | Quaternion at index i-1 |
[in] | qi | Quaternion at index i. |
[in] | qi_p1 | Quaternion at index i+1 |
[in] | qi_p2 | Quaternion at index i+2 |
[in] | t | Blend parameter [0.0, 1.0.] |
String ToString | ( | const FormatStatement * | formatStatement = nullptr | ) | const |
Returns a readable string of the content.
[in] | formatStatement | Nullptr or additional formatting instruction. See also Formatting Floating point values. |
|
static |
Describe all elements of this class for I/O operations.
[in] | stream | The stream that is used to register the class members. |
MAXON_OPERATOR_EQUALITY_HASHCODE | ( | Quaternion< ValueType > | , |
v | , | ||
w | |||
) |
|
friend |
Scales the components of a quaternion with a scalar.
direction vector component
ValueType w |
angle component