Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Static Protected Attributes | Friends | List of all members
Quaternion Class Reference

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...
 

Detailed Description

Quaternions.

Constructor & Destructor Documentation

◆ Quaternion() [1/4]

Quaternion::Quaternion ( const double &  w,
const double &  x,
const double &  y,
const double &  z 
)
inlineexplicit

Create a quaternion.

Parameters
wAngular parameter.
x,y,zAxis coordinates.

◆ Quaternion() [2/4]

Quaternion::Quaternion ( const Vector axis,
const double &  a 
)
explicit

Create a quaternion from an axis vector and a rotation angle.

Axis should be unit length.

Parameters
axisNormalized axis.
aAngle.

◆ Quaternion() [3/4]

Quaternion::Quaternion ( const Vector a,
const Vector b 
)
explicit

Create a quaternion from two (normalized) vectors representing the rotation.

Simply coded as:

Parameters
a,bVectors (should be unit).

◆ Quaternion() [4/4]

Quaternion::Quaternion ( const Matrix R)
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.

Parameters
RRotation matrix.

Member Function Documentation

◆ AngleAxis()

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).

Parameters
angleThe angle.
axisVector axis.

◆ Exp()

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).

◆ FromAngles()

Quaternion Quaternion::FromAngles ( const double &  a,
const double &  b,
const double &  c 
)
static

Create a quaternion from Euler rotation angles.

Using this function is simpler than calling the constructor from a rotation matrix.

Parameters
a,b,cRotation angles around x, y and z axes (should be in radian).

◆ Inverse()

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.

◆ Lerp()

Quaternion Quaternion::Lerp ( const double &  t,
const Quaternion p,
const Quaternion q 
)
static

Perform quaternion spherical interpolation, also known as slerping.

The dot product of argument quaternions should be positive.

Parameters
p,qArgument quaternions.
tInterpolating value.

◆ Log()

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.

◆ operator*() [1/3]

Quaternion Quaternion::operator* ( const double &  c) const
inline

Multiply a quaternion by a double value.

Parameters
cReal.

◆ operator*() [2/3]

Quaternion Quaternion::operator* ( const Quaternion q) const

Multiplication of two quaternion.

Note that multiplication is not generally commutative.

◆ operator*() [3/3]

Vector Quaternion::operator* ( const Vector p) const

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.

◆ operator[]()

constexpr double Quaternion::operator[] ( int  i) const
inlineconstexpr

Returns the i-th coefficient of a quaternion.

Terms are x, y, and z if index is in [0,2], and w otherwise.

Friends And Related Function Documentation

◆ Norm

double Norm ( const Quaternion q)
friend

Squared length of a quaternion.

Parameters
qQuaternion.

◆ operator*

Quaternion operator* ( const double &  c,
const Quaternion q 
)
friend

Left multiply a quaternion by a double value.

Parameters
cReal.
qQuaternion.

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Quaternion quaternion 
)
friend

Overloaded.

Parameters
sStream.
quaternionThe quaternion.