All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | List of all members
blaze::Quaternion< typename > Class Template Reference

Efficient implementation of a quaternion.Quaternions are a superior way to deal with rotations and orientations. This quaternion consists of 4 statically allocated elements, where the first element represents the real part and the three other elements represent the three imaginary parts. The naming convention of the elements is as following: More...

#include <Quaternion.h>

Public Types

typedef Type ElementType
 Type of the quaternion elements.
 

Public Member Functions

template<typename Type >
Quaternion< Type > & operator= (const Quaternion< Type > &rhs)
 Copy assignment operator for Quaternion. More...
 
template<typename Other >
Quaternion< Type > & operator= (const Quaternion< Other > &rhs)
 Assignment operator for different Quaternion instances. More...
 
Constructors
 Quaternion ()
 The default constructor for Quaternion. More...
 
 Quaternion (Type r, Type i, Type j, Type k)
 Constructor for a direct initialization of all quaternion elements. More...
 
template<typename Axis >
 Quaternion (StaticVector< Axis, 3UL, false > axis, Type angle)
 Constructor for a quaternion depending on a rotation axis and angle. More...
 
 Quaternion (Type xangle, Type yangle, Type zangle)
 Constructor for a quaternion rotated by the Euler angles xangle, yangle and zangle. More...
 
template<typename Other >
 Quaternion (const StaticVector< Other, 3UL, false > &euler)
 Constructor for a quaternion rotated by the Euler angles euler. More...
 
 Quaternion (const Quaternion &q)
 The copy constructor for Quaternion. More...
 
template<typename Other >
 Quaternion (const Quaternion< Other > &q)
 Conversion constructor from different Quaternion instances. More...
 
Operators
Quaternionoperator= (const Quaternion &rhs)
 
template<typename Other >
Quaternionoperator= (const Quaternion< Other > &rhs)
 
Type operator[] (size_t index) const
 Subscript operator for the direct access to the quaternion elements. More...
 
Utility functions
Quaternionset (Type r, Type i, Type j, Type k)
 Setting the value of the quaternion elements. More...
 
void reset ()
 Reset to the default initial values. More...
 
Type length () const
 Calculation of the quaternion length $|\hat{q}|$. More...
 
Quaternionnormalize ()
 Normalization of the quaternion ( $|\hat{q}|=1$). More...
 
const Quaternion getNormalized () const
 Calculation of the normalized quaternion ( $|\hat{q}|=1$). More...
 
Quaternioninvert ()
 Inversion of the quaternion ( $ \hat{q} = \hat{q}^{-1} $). More...
 
const RotationMatrix< Type > toRotationMatrix () const
 Conversion to a rotation matrix. More...
 
void rotateX (Type angle)
 Rotating the quaternion around the global x-axis by angle degrees (radian measure). More...
 
void rotateY (Type angle)
 Rotating the quaternion around the global y-axis by angle degrees (radian measure). More...
 
void rotateZ (Type angle)
 Rotating the quaternion around the global z-axis by angle degrees (radian measure). More...
 
void swap (Quaternion &q)
 Swapping the contents of two quaternions. More...
 
Math functions
template<typename Other , bool TF>
const StaticVector< typename
MultTrait< Type, Other >::Type, 3UL, false > 
rotate (const StaticVector< Other, 3UL, TF > &v) const
 Rotation of a vector v ( $ \vec{rot} = \hat{q} \cdot \vec{v} \cdot \hat{q}^{-1} $). More...
 
template<typename Other >
const StaticMatrix< typename
MultTrait< Type, Other >::Type, 3UL, 3UL, false > 
rotate (const StaticMatrix< Other, 3UL, 3UL, false > &m) const
 Rotation of a matrix. More...
 
template<typename Other >
const StaticMatrix< typename
MultTrait< Type, Other >::Type, 3UL, 3UL, false > 
diagRotate (const StaticMatrix< Other, 3UL, 3UL, false > &m) const
 Rotation of a diagonal matrix. More...
 
template<typename Other >
MathTrait< Type, Other >::HighType calcAngle (const StaticVector< Other, 3UL, false > &axis) const
 Returns the angle in radian measure between the quaterion and a given axis. More...
 

Private Attributes

Member variables
Type v_ [4]
 The four statically allocated quaternion elements. More...
 

Detailed Description

template<typename>
class blaze::Quaternion< typename >

Efficient implementation of a quaternion.

Quaternions are a superior way to deal with rotations and orientations. This quaternion consists of 4 statically allocated elements, where the first element represents the real part and the three other elements represent the three imaginary parts. The naming convention of the elements is as following:

\[\left(\begin{array}{*{4}{c}} r & i & j & k \\ \end{array}\right)\]

These elements can be accessed directly with the subscript operator. The numbering of the quaternion elements is

\[\left(\begin{array}{*{4}{c}} 0 & 1 & 2 & 3 \\ \end{array}\right)\]

Note: The Quaternion class can only be instantiated for non-cv-qualified floating point types! Therefore the only possible Quaternion instantiations are

The attempt to create a quaternion with an integral data type results in a compile time error.

Constructor & Destructor Documentation

template<typename Type >
blaze::Quaternion< Type >::Quaternion ( )
inlineexplicit

The default constructor for Quaternion.

The real part of the quaternion is initialized with 1, whereas the imaginary parts are initialized with 0:

\[ \left(\begin{array}{c} 1 \\ 0 \\ 0 \\ 0 \end{array}\right) \]

template<typename Type >
blaze::Quaternion< Type >::Quaternion ( Type  r,
Type  i,
Type  j,
Type  k 
)
inlineexplicit

Constructor for a direct initialization of all quaternion elements.

Parameters
rThe initial value for the real part.
iThe initial value for the first imaginary part.
jThe initial value for the second imaginary part.
kThe initial value for the third imaginary part.

The initial values for the quaterion have to be chosen such that the length of the quaternion is 1.

template<typename Type >
template<typename Axis >
blaze::Quaternion< Type >::Quaternion ( StaticVector< Axis, 3UL, false >  axis,
Type  angle 
)
inlineexplicit

Constructor for a quaternion depending on a rotation axis and angle.

Parameters
axisThe rotation axis.
angleThe rotation angle (radian measure).

This constructor creates a quaternion from the rotation axis axis and the rotation angle angle. axis may be an arbitrary, non-zero vector of any length. However, it is allowed to use the zero vector (0,0,0) in combination with an angle of 0. This combination results in a default quaternion

\[ \left(\begin{array}{c} 1 \\ 0 \\ 0 \\ 0 \end{array}\right) \]

template<typename Type >
blaze::Quaternion< Type >::Quaternion ( Type  xangle,
Type  yangle,
Type  zangle 
)
inlineexplicit

Constructor for a quaternion rotated by the Euler angles xangle, yangle and zangle.

Parameters
xangleRotation around the x-axis (radian measure).
yangleRotation around the y-axis (radian measure).
zangleRotation around the z-axis (radian measure).

This constructor creates a quaternion rotated by the Euler angles xangle, yangle and zangle (all in radian measure). The rotations are applied in the order x, y, and z.

template<typename Type >
template<typename Other >
blaze::Quaternion< Type >::Quaternion ( const StaticVector< Other, 3UL, false > &  euler)
inlineexplicit

Constructor for a quaternion rotated by the Euler angles euler.

Parameters
euler3-dimensional vector of the three rotation angles (radian measure).

This constructor creates a quaternion rotated by the Euler angles euler (all components in radian measure). The rotations are applied in the order x, y, and z.

template<typename Type >
blaze::Quaternion< Type >::Quaternion ( const Quaternion< typename > &  q)
inline

The copy constructor for Quaternion.

Parameters
qQuaternion to be copied.

The copy constructor is explicitly defined in order to enable/facilitate NRV optimization.

template<typename Type >
template<typename Other >
blaze::Quaternion< Type >::Quaternion ( const Quaternion< Other > &  q)
inline

Conversion constructor from different Quaternion instances.

Parameters
qQuaternion to be copied.

Member Function Documentation

template<typename Type >
template<typename Other >
MathTrait< Type, Other >::HighType blaze::Quaternion< Type >::calcAngle ( const StaticVector< Other, 3UL, false > &  axis) const
inline

Returns the angle in radian measure between the quaterion and a given axis.

Parameters
axisThe given axis.
Returns
The angle in radian measure.
template<typename Type >
template<typename Other >
const StaticMatrix< typename MultTrait< Type, Other >::Type, 3UL, 3UL, false > blaze::Quaternion< Type >::diagRotate ( const StaticMatrix< Other, 3UL, 3UL, false > &  m) const
inline

Rotation of a diagonal matrix.

Parameters
mThe diagonal matrix to be rotated.
Returns
The rotated matrix.

The DiagRotate function is a special case of the rotate function. The matrix is assumed to be a diagonal matrix, which reduces the number of floating point operations of the rotation. The function is selected for matrices of different data type (in case Type and Other are supported by the MultTrait class). The function returns a matrix of the higher-order data type of the two involved data types.

template<typename Type >
const Quaternion< Type > blaze::Quaternion< Type >::getNormalized ( ) const
inline

Calculation of the normalized quaternion ( $|\hat{q}|=1$).

Returns
The normalized quaternion.
template<typename Type >
Quaternion< Type > & blaze::Quaternion< Type >::invert ( )
inline

Inversion of the quaternion ( $ \hat{q} = \hat{q}^{-1} $).

Returns
Reference to the inverted quaternion.
template<typename Type >
Type blaze::Quaternion< Type >::length ( ) const
inline

Calculation of the quaternion length $|\hat{q}|$.

Returns
The length of the quaternion.
template<typename Type >
Quaternion< Type > & blaze::Quaternion< Type >::normalize ( )
inline

Normalization of the quaternion ( $|\hat{q}|=1$).

Returns
Reference to the quaternion.
template<typename >
template<typename Type >
Quaternion<Type>& blaze::Quaternion< typename >::operator= ( const Quaternion< Type > &  rhs)
inline

Copy assignment operator for Quaternion.

Parameters
rhsQuaternion to be copied.
Returns
Reference to the assigned quaternion.

Explicit definition of a copy assignment operator for performance reasons.

template<typename >
template<typename Other >
Quaternion<Type>& blaze::Quaternion< typename >::operator= ( const Quaternion< Other > &  rhs)
inline

Assignment operator for different Quaternion instances.

Parameters
rhsQuaternion to be copied.
Returns
Reference to the assigned quaternion.
template<typename Type >
Type blaze::Quaternion< Type >::operator[] ( size_t  index) const
inline

Subscript operator for the direct access to the quaternion elements.

Parameters
indexAccess index. The index has to be in the range $[0..3]$.
Returns
Copy of the accessed element.

In case BLAZE_USER_ASSERT() is active, this operator performs an index check.

template<typename Type >
void blaze::Quaternion< Type >::reset ( )
inline

Reset to the default initial values.

Returns
void

This function resets the quaternion to the default initial values. The real part of the quaternion is reset to 1, whereas the imaginary parts are reset to 0:

\[\left(\begin{array}{*{4}{c}} 1 & 0 & 0 & 0 \\ \end{array}\right)\]

template<typename Type >
template<typename Other , bool TF>
const StaticVector< typename MultTrait< Type, Other >::Type, 3UL, false > blaze::Quaternion< Type >::rotate ( const StaticVector< Other, 3UL, TF > &  v) const
inline

Rotation of a vector v ( $ \vec{rot} = \hat{q} \cdot \vec{v} \cdot \hat{q}^{-1} $).

Parameters
vThe vector to be rotated.
Returns
The rotated vector.

The function is selected for vectors of different data type (in case Type and Other are supported by the MultTrait class). The function returns a vector of the higher-order data type of the two involved data types.

template<typename Type >
template<typename Other >
const StaticMatrix< typename MultTrait< Type, Other >::Type, 3UL, 3UL, false > blaze::Quaternion< Type >::rotate ( const StaticMatrix< Other, 3UL, 3UL, false > &  m) const
inline

Rotation of a matrix.

Parameters
mThe matrix to be rotated.
Returns
The rotated matrix.

The function is selected for matrices of different data type (in case Type and Other are supported by the MultTrait class). The function returns a matrix of the higher-order data type of the two involved data types.

template<typename Type >
void blaze::Quaternion< Type >::rotateX ( Type  angle)
inline

Rotating the quaternion around the global x-axis by angle degrees (radian measure).

Parameters
angleThe rotation angle (radian measure).
Returns
void
template<typename Type >
void blaze::Quaternion< Type >::rotateY ( Type  angle)
inline

Rotating the quaternion around the global y-axis by angle degrees (radian measure).

Parameters
angleThe rotation angle (radian measure).
Returns
void
template<typename Type >
void blaze::Quaternion< Type >::rotateZ ( Type  angle)
inline

Rotating the quaternion around the global z-axis by angle degrees (radian measure).

Parameters
angleThe rotation angle (radian measure).
Returns
void
template<typename Type >
Quaternion< Type > & blaze::Quaternion< Type >::set ( Type  r,
Type  i,
Type  j,
Type  k 
)
inline

Setting the value of the quaternion elements.

Parameters
rThe value for the real part.
iThe value for the first imaginary part.
jThe value for the second imaginary part.
kThe value for the third imaginary part.
template<typename Type >
void blaze::Quaternion< Type >::swap ( Quaternion< typename > &  q)
inline

Swapping the contents of two quaternions.

Parameters
qThe quaternion to be swapped.
Returns
void
Exceptions
no-throwguarantee.
template<typename Type >
const RotationMatrix< Type > blaze::Quaternion< Type >::toRotationMatrix ( ) const
inline

Conversion to a rotation matrix.

Returns
The resulting rotation matrix.

Member Data Documentation

template<typename >
Type blaze::Quaternion< typename >::v_[4]
private

The four statically allocated quaternion elements.

Access to the quaternion values is gained via the subscript operator. The order of the elements is

\[\left(\begin{array}{*{4}{c}} 0 & 1 & 2 & 3 \\ \end{array}\right)\]


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