vmath  vmath-0.12
Quaternion< T > Class Template Reference

Quaternion class implementing some quaternion algebra operations. More...

#include <vmath.h>

+ Collaboration diagram for Quaternion< T >:

Public Member Functions

 Quaternion ()
 Quaternion constructor, sets quaternion to (0 + 0i + 0j + 0k). More...
 
 Quaternion (const Quaternion< T > &q)
 Copy constructor. More...
 
template<class FromT >
 Quaternion (const Quaternion< FromT > &q)
 Copy casting constructor. More...
 
 Quaternion (T w_, const Vector3< T > &v_)
 Creates quaternion object from real part w_ and complex part v_. More...
 
 Quaternion (T w_, T x, T y, T z)
 Creates quaternion object from value (w_ + xi + yj + zk). More...
 
Quaternion< T > & operator= (const Quaternion< T > &rhs)
 Copy operator. More...
 
template<class FromT >
Quaternion< T > & operator= (const Quaternion< FromT > &rhs)
 Copy convert operator. More...
 
Quaternion< T > operator+ (const Quaternion< T > &rhs) const
 Addition operator. More...
 
Quaternion< T > operator* (const Quaternion< T > &rhs) const
 Multiplication operator. More...
 
Quaternion< T > operator* (T rhs) const
 Multiplication operator. More...
 
Quaternion< T > operator- (const Quaternion< T > &rhs) const
 Subtraction operator. More...
 
Quaternion< T > & operator+= (const Quaternion< T > &rhs)
 Addition operator. More...
 
Quaternion< T > & operator-= (const Quaternion< T > &rhs)
 Subtraction operator. More...
 
Quaternion< T > & operator*= (const Quaternion< T > &rhs)
 Multiplication operator. More...
 
Quaternion< T > & operator*= (T rhs)
 Multiplication operator. More...
 
bool operator== (const Quaternion< T > &rhs) const
 Equality test operator. More...
 
bool operator!= (const Quaternion< T > &rhs) const
 Inequality test operator. More...
 
Quaternion< T > operator- () const
 Unary negate operator. More...
 
Quaternion< T > operator~ () const
 Unary conjugate operator. More...
 
length () const
 Get lenght of quaternion. More...
 
lengthSq () const
 Return square of length. More...
 
void normalize ()
 Normalize quaternion. More...
 
Matrix3< T > rotMatrix ()
 Converts quaternion into rotation matrix. More...
 
Matrix4< T > transform () const
 Converts quaternion into transformation matrix. More...
 
Quaternion< T > lerp (T fact, const Quaternion< T > &rhs) const
 Linear interpolation of two quaternions. More...
 
std::string toString () const
 Gets string representation. More...
 
Quaternion< T > slerp (T r, const Quaternion< T > &q2) const
 Computes spherical interpolation between quaternions (this, q2) using coefficient of interpolation r (in [0, 1]). More...
 

Static Public Member Functions

static Quaternion< T > fromEulerAngles (T x, T y, T z)
 Creates quaternion for eulers angles. More...
 
static Quaternion< T > fromAxisRot (Vector3< T > axis, float angleDeg)
 Creates quaternion as rotation around axis. More...
 
static Quaternion< T > fromMatrix (const Matrix4< T > &m)
 Creates quaternion from transform matrix. More...
 
static Quaternion< T > fromMatrix (const Matrix3< T > &m)
 Creates quaternion from rotation matrix. More...
 

Public Attributes

w
 Real part of quaternion. More...
 
Vector3< T > v
 Imaginary part of quaternion. More...
 

Friends

std::ostream & operator<< (std::ostream &oss, const Quaternion< T > &q)
 Provides output to standard output stream. More...
 

Detailed Description

template<class T>
class 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.

Constructor & Destructor Documentation

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

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

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

Copy constructor.

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

Copy casting constructor.

template<class T>
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).
template<class T>
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.

Member Function Documentation

template<class T>
static Quaternion<T> 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).
template<class T>
static Quaternion<T> 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.
template<class T>
static Quaternion<T> 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.
template<class T>
static Quaternion<T> 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.
template<class T>
T Quaternion< T >::length ( ) const
inline

Get lenght of quaternion.

Returns
Length of quaternion.
template<class T>
T 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.
template<class T>
Quaternion<T> 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?)
template<class T>
void Quaternion< T >::normalize ( )
inline

Normalize quaternion.

template<class T>
bool 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
template<class T>
Quaternion<T> Quaternion< T >::operator* ( const Quaternion< T > &  rhs) const
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T> Quaternion< T >::operator* ( rhs) const
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T>& Quaternion< T >::operator*= ( const Quaternion< T > &  rhs)
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T>& Quaternion< T >::operator*= ( rhs)
inline

Multiplication operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T> Quaternion< T >::operator+ ( const Quaternion< T > &  rhs) const
inline

Addition operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T>& Quaternion< T >::operator+= ( const Quaternion< T > &  rhs)
inline

Addition operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T> Quaternion< T >::operator- ( const Quaternion< T > &  rhs) const
inline

Subtraction operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T> Quaternion< T >::operator- ( ) const
inline

Unary negate operator.

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

Subtraction operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
Quaternion<T>& Quaternion< T >::operator= ( const Quaternion< T > &  rhs)
inline

Copy operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
template<class FromT >
Quaternion<T>& Quaternion< T >::operator= ( const Quaternion< FromT > &  rhs)
inline

Copy convert operator.

Parameters
rhsRight hand side argument of binary operator.
template<class T>
bool 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.
template<class T>
Quaternion<T> Quaternion< T >::operator~ ( ) const
inline

Unary conjugate operator.

Returns
conjugated quaternion
template<class T>
Matrix3<T> Quaternion< T >::rotMatrix ( )
inline

Converts quaternion into rotation matrix.

Returns
Rotation matrix expressing this quaternion.
template<class T>
Quaternion<T> 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.
template<class T>
std::string Quaternion< T >::toString ( ) const
inline

Gets string representation.

template<class T>
Matrix4<T> 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.

Friends And Related Function Documentation

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

Provides output to standard output stream.

Member Data Documentation

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

Imaginary part of quaternion.

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

Real part of quaternion.


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