VMTK
VMATH_NAMESPACE::Quaternion< T > Class Template Reference

#include <vmath.h>

Public Member Functions

 Quaternion ()
 
 Quaternion (const Quaternion< T > &q)
 
template<class FromT >
 Quaternion (const Quaternion< FromT > &q)
 
 Quaternion (T w_, const Vector3< T > &v_)
 
 Quaternion (T w_, T x, T y, T z)
 
Quaternion< T > & operator= (const Quaternion< T > &rhs)
 
template<class FromT >
Quaternion< T > & operator= (const Quaternion< FromT > &rhs)
 
Quaternion< T > operator+ (const Quaternion< T > &rhs) const
 
Quaternion< T > operator* (const Quaternion< T > &rhs) const
 
Quaternion< T > operator* (T rhs) const
 
Quaternion< T > operator- (const Quaternion< T > &rhs) const
 
Quaternion< T > & operator+= (const Quaternion< T > &rhs)
 
Quaternion< T > & operator-= (const Quaternion< T > &rhs)
 
Quaternion< T > & operator*= (const Quaternion< T > &rhs)
 
Quaternion< T > & operator*= (T rhs)
 
bool operator== (const Quaternion< T > &rhs) const
 
bool operator!= (const Quaternion< T > &rhs) const
 
Quaternion< T > operator- () const
 
Quaternion< T > operator~ () const
 
length () const
 
lengthSq () const
 
void normalize ()
 
Matrix3< T > rotMatrix ()
 
Matrix4< T > transform () const
 
Quaternion< T > lerp (T fact, const Quaternion< T > &rhs) const
 
std::string toString () const
 
Quaternion< T > slerp (T r, const Quaternion< T > &q2) const
 

Static Public Member Functions

static Quaternion< T > fromEulerAngles (T x, T y, T z)
 
static Quaternion< T > fromAxisRot (Vector3< T > axis, float angleDeg)
 
static Quaternion< T > fromMatrix (const Matrix4< T > &m)
 
static Quaternion< T > fromMatrix (const Matrix3< T > &m)
 

Public Attributes

w
 
Vector3< T > v
 

Friends

std::ostream & operator<< (std::ostream &oss, const Quaternion< T > &q)
 

Detailed Description

template<class T>
class VMATH_NAMESPACE::Quaternion< T >

Quaternion class implementing some quaternion algebra operations. Quaternion is kind of complex number it consists of its real part (w) and its complex part v. This complex part has three elements, so we can express it as xi + yj + zk . Note that coordinates of (x,y,z) are hold inside v field.

Definition at line 3342 of file vmath.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/5]

template<class T>
VMATH_NAMESPACE::Quaternion< T >::Quaternion ( )
inline

Quaternion constructor, sets quaternion to (0 + 0i + 0j + 0k).

Definition at line 3357 of file vmath.h.

◆ Quaternion() [2/5]

template<class T>
VMATH_NAMESPACE::Quaternion< T >::Quaternion ( const Quaternion< T > &  q)
inline

Copy constructor.

Definition at line 3365 of file vmath.h.

◆ Quaternion() [3/5]

template<class T>
template<class FromT >
VMATH_NAMESPACE::Quaternion< T >::Quaternion ( const Quaternion< FromT > &  q)
inline

Copy casting constructor.

Definition at line 3374 of file vmath.h.

◆ Quaternion() [4/5]

template<class T>
VMATH_NAMESPACE::Quaternion< T >::Quaternion ( w_,
const Vector3< T > &  v_ 
)
inline

Creates quaternion object from real part w_ and complex part v_.

Parameters
w_Real part of quaternion.
v_Complex part of quaternion (xi + yj + zk).

Definition at line 3384 of file vmath.h.

◆ Quaternion() [5/5]

template<class T>
VMATH_NAMESPACE::Quaternion< T >::Quaternion ( w_,
x,
y,
z 
)
inline

Creates quaternion object from value (w_ + xi + yj + zk).

Parameters
w_Real part of quaternion.
xComplex coefficient for i complex constant.
yComplex coefficient for j complex constant.
zComplex coefficient for k complex constant.

Definition at line 3396 of file vmath.h.

Member Function Documentation

◆ fromAxisRot()

template<class T>
static Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::fromAxisRot ( Vector3< T >  axis,
float  angleDeg 
)
inlinestatic

Creates quaternion as rotation around axis.

Parameters
axisUnit vector expressing axis of rotation.
angleDegAngle of rotation around axis (in degrees).

Definition at line 3603 of file vmath.h.

◆ fromEulerAngles()

template<class T>
static Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::fromEulerAngles ( x,
y,
z 
)
inlinestatic

Creates quaternion for eulers angles.

Parameters
xRotation around x axis (in degrees).
yRotation around y axis (in degrees).
zRotation around z axis (in degrees).
Returns
Quaternion object representing transformation.

Definition at line 3591 of file vmath.h.

◆ fromMatrix() [1/2]

template<class T>
static Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::fromMatrix ( const Matrix4< T > &  m)
inlinestatic

Creates quaternion from transform matrix.

Parameters
mTransform matrix used to compute quaternion.
Returns
Quaternion representing rotation of matrix m.

Definition at line 3744 of file vmath.h.

◆ fromMatrix() [2/2]

template<class T>
static Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::fromMatrix ( const Matrix3< T > &  m)
inlinestatic

Creates quaternion from rotation matrix.

Parameters
mRotation matrix used to compute quaternion.
Returns
Quaternion representing rotation of matrix m.

Definition at line 3803 of file vmath.h.

◆ length()

template<class T>
T VMATH_NAMESPACE::Quaternion< T >::length ( ) const
inline

Get lenght of quaternion.

Returns
Length of quaternion.

Definition at line 3557 of file vmath.h.

Here is the call graph for this function:

◆ lengthSq()

template<class T>
T VMATH_NAMESPACE::Quaternion< T >::lengthSq ( ) const
inline

Return square of length.

Returns
length ^ 2
Note
This method is faster then length(). For comparison of length of two quaternion can be used just this value, instead of more expensive length() method.

Definition at line 3569 of file vmath.h.

Here is the call graph for this function:

◆ lerp()

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::lerp ( fact,
const Quaternion< T > &  rhs 
) const
inline

Linear interpolation of two quaternions

Parameters
factFactor of interpolation. For translation from position of this vector to quaternion rhs, values of factor goes from 0.0 to 1.0.
rhsSecond Quaternion for interpolation
Note
However values of fact parameter are reasonable only in interval [0.0 , 1.0], you can pass also values outside of this interval and you can get result (extrapolation?)

Definition at line 3713 of file vmath.h.

Here is the call graph for this function:

◆ normalize()

template<class T>
void VMATH_NAMESPACE::Quaternion< T >::normalize ( )
inline

Normalize quaternion

Definition at line 3577 of file vmath.h.

Here is the call graph for this function:

◆ operator!=()

template<class T>
bool VMATH_NAMESPACE::Quaternion< T >::operator!= ( const Quaternion< T > &  rhs) const
inline

Inequality test operator

Parameters
rhsRight hand side argument of binary operator.
Returns
not (lhs == rhs) :-P

Definition at line 3529 of file vmath.h.

◆ operator*() [1/2]

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::operator* ( const Quaternion< T > &  rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3438 of file vmath.h.

◆ operator*() [2/2]

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::operator* ( rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3451 of file vmath.h.

◆ operator*=() [1/2]

template<class T>
Quaternion<T>& VMATH_NAMESPACE::Quaternion< T >::operator*= ( const Quaternion< T > &  rhs)
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3492 of file vmath.h.

◆ operator*=() [2/2]

template<class T>
Quaternion<T>& VMATH_NAMESPACE::Quaternion< T >::operator*= ( rhs)
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3504 of file vmath.h.

◆ operator+()

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::operator+ ( const Quaternion< T > &  rhs) const
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3428 of file vmath.h.

◆ operator+=()

template<class T>
Quaternion<T>& VMATH_NAMESPACE::Quaternion< T >::operator+= ( const Quaternion< T > &  rhs)
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3470 of file vmath.h.

◆ operator-() [1/2]

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::operator- ( const Quaternion< T > &  rhs) const
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3460 of file vmath.h.

◆ operator-() [2/2]

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::operator- ( ) const
inline

Unary negate operator

Returns
negated quaternion

Definition at line 3539 of file vmath.h.

◆ operator-=()

template<class T>
Quaternion<T>& VMATH_NAMESPACE::Quaternion< T >::operator-= ( const Quaternion< T > &  rhs)
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3481 of file vmath.h.

◆ operator=() [1/2]

template<class T>
Quaternion<T>& VMATH_NAMESPACE::Quaternion< T >::operator= ( const Quaternion< T > &  rhs)
inline

Copy operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3405 of file vmath.h.

◆ operator=() [2/2]

template<class T>
template<class FromT >
Quaternion<T>& VMATH_NAMESPACE::Quaternion< T >::operator= ( const Quaternion< FromT > &  rhs)
inline

Copy convert operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3417 of file vmath.h.

◆ operator==()

template<class T>
bool VMATH_NAMESPACE::Quaternion< T >::operator== ( const Quaternion< T > &  rhs) const
inline

Equality test operator

Parameters
rhsRight hand side argument of binary operator.
Note
Test of equality is based of threshold EPSILON value. To be two values equal, must satisfy this condition | lhs - rhs | < EPSILON, for all quaternion coordinates.

Definition at line 3518 of file vmath.h.

◆ operator~()

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::operator~ ( ) const
inline

Unary conjugate operator

Returns
conjugated quaternion

Definition at line 3548 of file vmath.h.

◆ rotMatrix()

template<class T>
Matrix3<T> VMATH_NAMESPACE::Quaternion< T >::rotMatrix ( )
inline

Converts quaternion into rotation matrix.

Returns
Rotation matrix expressing this quaternion.

Definition at line 3615 of file vmath.h.

Here is the call graph for this function:

◆ slerp()

template<class T>
Quaternion<T> VMATH_NAMESPACE::Quaternion< T >::slerp ( r,
const Quaternion< T > &  q2 
) const
inline

Computes spherical interpolation between quaternions (this, q2) using coefficient of interpolation r (in [0, 1]).

Parameters
rThe ratio of interpolation form this (r = 0) to q2 (r = 1).
q2Second quaternion for interpolation.
Returns
Result of interpolation.

Definition at line 3862 of file vmath.h.

Here is the call graph for this function:

◆ toString()

template<class T>
std::string VMATH_NAMESPACE::Quaternion< T >::toString ( ) const
inline

Gets string representation.

Definition at line 3730 of file vmath.h.

◆ transform()

template<class T>
Matrix4<T> VMATH_NAMESPACE::Quaternion< T >::transform ( ) const
inline

Converts quaternion into transformation matrix.

Note
This method performs same operation as rotMatrix() conversion method. But returns Matrix of 4x4 elements.
Returns
Transformation matrix expressing this quaternion.

Definition at line 3664 of file vmath.h.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

template<class T>
std::ostream& operator<< ( std::ostream &  oss,
const Quaternion< T > &  q 
)
friend

Provides output to standard output stream.

Definition at line 3721 of file vmath.h.

Member Data Documentation

◆ v

template<class T>
Vector3<T> VMATH_NAMESPACE::Quaternion< T >::v

Imaginary part of quaternion.

Definition at line 3352 of file vmath.h.

◆ w

template<class T>
T VMATH_NAMESPACE::Quaternion< T >::w

Real part of quaternion.

Definition at line 3348 of file vmath.h.


The documentation for this class was generated from the following file: