Public Member Functions | Static Public Member Functions | Public Attributes | Friends

Quaternion< T > Class Template Reference

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

#include <vmath.h>

Collaboration diagram for Quaternion< T >:

List of all members.

Public Member Functions

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

Static Public Member Functions

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

Public Attributes

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

Friends

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

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.
x Complex coefficient for i complex constant.
y Complex coefficient for j complex constant.
z Complex coefficient for k complex constant.

Member Function Documentation

template<class T>
static Quaternion<T> Quaternion< T >::fromAxisRot ( Vector3< T >  axis,
float  angleDeg 
) [inline, static]

Creates quaternion as rotation around axis.

Parameters:
axis Unit vector expressing axis of rotation.
angleDeg Angle of rotation around axis (in degrees).
template<class T>
static Quaternion<T> Quaternion< T >::fromEulerAngles ( x,
y,
z 
) [inline, static]

Creates quaternion for eulers angles.

Parameters:
x Rotation around x axis (in degrees).
y Rotation around y axis (in degrees).
z Rotation around z axis (in degrees).
Returns:
Quaternion object representing transformation.
template<class T>
static Quaternion<T> Quaternion< T >::fromMatrix ( const Matrix4< T > &  m  )  [inline, static]

Creates quaternion from transform matrix.

Parameters:
m Transform 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  )  [inline, static]

Creates quaternion from rotation matrix.

Parameters:
m Rotation 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:
fact Factor of interpolation. For translation from position of this vector to quaternion rhs, values of factor goes from 0.0 to 1.0.
rhs Second 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:
rhs Right hand side argument of binary operator.
Returns:
not (lhs == rhs) :-P
template<class T>
Quaternion<T> Quaternion< T >::operator* ( rhs  )  const [inline]

Multiplication operator.

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

Multiplication operator.

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

Multiplication operator.

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

Multiplication operator.

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

Addition operator.

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

Addition operator.

Parameters:
rhs Right 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  )  const [inline]

Subtraction operator.

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

Subtraction operator.

Parameters:
rhs Right 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:
rhs Right hand side argument of binary operator.
template<class T>
Quaternion<T>& Quaternion< T >::operator= ( const Quaternion< T > &  rhs  )  [inline]

Copy operator.

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

Equality test operator.

Parameters:
rhs Right 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:
r The ratio of interpolation form this (r = 0) to q2 (r = 1).
q2 Second 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: