Core 1.0
|
Quaternions. More...
#include <quaternion.h>
Public Member Functions | |
Quaternion () | |
Empty. | |
Quaternion (const double &, const double &, const double &, const double &) | |
Create a quaternion. More... | |
Quaternion (const Vector &, const double &) | |
Create a quaternion from an axis vector and a rotation angle. More... | |
Quaternion (const Vector &, const Vector &) | |
Create a quaternion from two (normalized) vectors representing the rotation. More... | |
Quaternion (const Matrix &) | |
Create a quaternion from a rotation matrix. More... | |
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. More... | |
double & | operator[] (int) |
Overloaded. | |
constexpr double | operator[] (int) const |
Returns the i-th coefficient of a quaternion. More... | |
Quaternion | operator+ (const Quaternion &) const |
Overloaded. | |
Quaternion | operator- (const Quaternion &) const |
Overloaded. | |
Quaternion | operator* (const Quaternion &) const |
Multiplication of two quaternion. More... | |
Quaternion | operator* (const double &) const |
Multiply a quaternion by a double value. More... | |
Quaternion | operator- () const |
Overloaded. | |
Quaternion | Inverse () const |
Compute the inverse of a quaternion. More... | |
Quaternion | Conjugate () const |
Computes the conjugatge of a quaternion. | |
Quaternion | Exp () const |
Compute the exponential of a quaternion. More... | |
Quaternion | Log () const |
Computes the logarithm of a quaternion. More... | |
Vector | operator* (const Vector &) const |
Compute the product between a quaternion and a vector. More... | |
Static Public Member Functions | |
static Quaternion | Lerp (const double &, const Quaternion &, const Quaternion &) |
Perform quaternion spherical interpolation, also known as slerping. More... | |
static Quaternion | FromAngles (const double &, const double &, const double &) |
Create a quaternion from Euler rotation angles. More... | |
Static Public Attributes | |
static const Quaternion | Null |
Null quaternion. | |
static const Quaternion | Identity |
Identity. | |
Protected Attributes | |
double | z = 0.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 &, const Quaternion &) |
Left multiply a quaternion by a double value. More... | |
double | Norm (const Quaternion &) |
Squared length of a quaternion. More... | |
std::ostream & | operator<< (std::ostream &, const Quaternion &) |
Overloaded. More... | |
Quaternions.
|
inlineexplicit |
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 quaternion from two (normalized) vectors representing the rotation.
Simply coded as:
a,b | Vectors (should be unit). |
|
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.
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). |
Quaternion Quaternion::Inverse | ( | ) | const |
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.
|
static |
Perform quaternion spherical interpolation, also known as slerping.
The dot product of argument quaternions should be positive.
p,q | Argument quaternions. |
t | Interpolating value. |
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.
|
inline |
Multiply a quaternion by a double value.
c | Real. |
Quaternion Quaternion::operator* | ( | const Quaternion & | q | ) | const |
Multiplication of two quaternion.
Note that multiplication is not generally commutative.
Compute the product between a quaternion and a vector.
This member calls Quaternion::RotationMatrix(). As such, the quaternion representation of a rotation matrix requires less space than the matrix and more time to compute the rotated vector. This is a typical space-time tradeoff.
|
inlineconstexpr |
Returns the i-th coefficient of a quaternion.
Terms are x, y, and z if index is in [0,2], and w otherwise.
|
friend |
Squared 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. |