Murl::Math::Quaternion< DataType > Class Template Reference

A quaternion class. More...

#include "murl_math_quaternion.h"

Public Types

enum  Component {
  R , I , J , K ,
  NUM_COMPONENTS
}
 Enumeration of the components raw data index. More...
 
enum  ComponentMask {
  MASK_NONE , MASK_R , MASK_I , MASK_J ,
  MASK_K , MASK_IJK , MASK_ALL
}
 Enumeration of the components' bit masks. More...
 
enum  PredefinedType { UNINITIALIZED , IDENTITY }
 Enumeration of the predefined initialization types for constructing a Quaternion(PredefinedType type). More...
 
using ValueType = DataType
 The template parameter value type.
 

Public Member Functions

 Quaternion ()
 The default constructor.
 
 Quaternion (DataType vr, DataType vi, DataType vj, DataType vk)
 Constructor to initialize a quaternion with given component values. More...
 
 Quaternion (const Vector< DataType > &v)
 Constructor to initialize a quaternion from a given 4-vector containing a normalized rotation axis in its x,y and z components, and a rotation angle in its w component. More...
 
 Quaternion (DataType angle, const Vector< DataType > &axis)
 Constructor to initialize a quaternion from a given rotation angle and a normalized axis vector. More...
 
 Quaternion (const Matrix< DataType > &m)
 Constructor to initialize a quaternion from the rotation component of a given 4x4 matrix. More...
 
 Quaternion (PredefinedType type)
 Constructor to create a quaternion from a predefined type. More...
 
template<class DataType2 >
 Quaternion (const Quaternion< DataType2 > &q)
 The copy constructor using a quaternion of different type. More...
 
const DataType & operator[] (UInt32 index) const
 Get a const reference to one of the 4 component values. More...
 
DataType & operator[] (UInt32 index)
 Get a reference to one of the 4 component values. More...
 
const DataType * GetPointer () const
 Get a const pointer to the raw data. More...
 
DataType * GetPointer ()
 Get a pointer to the raw data. More...
 
void Set (const Matrix< DataType > &m)
 Set the quaternion from the rotation component of a given 4D matrix. More...
 
Quaternionoperator= (const Vector< DataType > &v)
 Assignment operator to convert a 4D vector to a 4D quaternion. More...
 
Quaternionoperator= (const Matrix< DataType > &m)
 Assignment operator to convert a 4D matrix to a 4D quaternion. More...
 
Quaternionoperator+= (const Quaternion &q)
 In-place addition operator. More...
 
Quaternionoperator*= (const Quaternion &q)
 In-place subtraction operator. More...
 
Quaternionoperator*= (const Vector< DataType > &v)
 In-place quaternion-vector multiplication operator. More...
 
Quaternionoperator*= (DataType d)
 In-place multiplication operator (scaling). More...
 
Quaternion operator+ (const Quaternion &rhs) const
 Addition operator. More...
 
Quaternion operator* (const Quaternion &rhs) const
 Quaternion-quaternion multiplication operator. More...
 
Quaternion operator* (const Vector< DataType > &rhs) const
 Quaternion-vector multiplication operator. More...
 
Quaternion operator* (DataType rhs) const
 Multiplication (scaling) operator. More...
 
void Clear ()
 Clear all components of the quaternion instance. More...
 
void Set (const Quaternion &q)
 Copy the content of a source quaternion to the quaternion instance. More...
 
void Set (DataType vr, DataType vi, DataType vj, DataType vk)
 Set all components of the quaternion instance to a set of given component values. More...
 
void InvertSelf ()
 In-place inversion.
 
void AddSelf (const Quaternion &q)
 In-place addition. More...
 
void MultiplySelf (const Quaternion &q)
 In-place Quaternion-quaternion multiplication. More...
 
void MultiplySelf (const Vector< DataType > &v)
 In-place Quaternion-vector multiplication. More...
 
void MultiplySelf (DataType d)
 In-place multiplication (scaling). More...
 
void NormalizeSelf ()
 In-place normalization of the quaternion instance.
 
Quaternion Invert () const
 Get the inverse of a quaternion. More...
 
Quaternion Add (const Quaternion &q) const
 Get the addition of a quaternion. More...
 
Quaternion Multiply (const Quaternion &q) const
 Get the multiplication with a quaternion. More...
 
Quaternion Multiply (const Vector< DataType > &v) const
 Get the multiplication with a vector. More...
 
Quaternion Multiply (DataType d) const
 Get the multiplication (scaling). More...
 
Quaternion Normalize () const
 Get the normalization of the quaternion instance. More...
 
Quaternion Interpolate (const Quaternion &q, DataType t, Bool spherical) const
 Interpolate between this instance and a second quaternion. More...
 
Bool IsEqual (const Quaternion &q) const
 Check if the quaternion instance is equal to a given second quaternion. More...
 
Bool IsEqual (const Quaternion &q, DataType epsilon) const
 Check if the quaternion instance is equal to a given second quaternion. More...
 
String ToString () const
 Get the string representation of the object. More...
 
SInt32 GetCount () const
 Get the number of elements in the object. More...
 

Public Attributes

union {
   DataType   mComponents [NUM_COMPONENTS]
 The components data array.
 
   struct {
      DataType   r
 The R component.
 
      DataType   i
 The I component.
 
      DataType   j
 The J component.
 
      DataType   k
 The K component.
 
   } 
 The components member struct.
 
}; 
 The components storage union overlaps the raw data array mComponents and the component structure.
 

Friends

bool operator== (const Quaternion< DataType > &lhs, const Quaternion< DataType > &rhs)
 Equal to comparison operator. More...
 
bool operator!= (const Quaternion< DataType > &lhs, const Quaternion< DataType > &rhs)
 Not equal to comparison operator. More...
 

Detailed Description

template<class DataType>
class Murl::Math::Quaternion< DataType >

A quaternion class.

Member Enumeration Documentation

◆ Component

template<class DataType >
enum Murl::Math::Quaternion::Component

Enumeration of the components raw data index.

The components can be accessed by using the [] operator.

Enumerator

The index to the R component.

The index to the I component.

The index to the J component.

The index to the K component.

NUM_COMPONENTS 

The number of components.

◆ ComponentMask

template<class DataType >
enum Murl::Math::Quaternion::ComponentMask

Enumeration of the components' bit masks.

Enumerator
MASK_NONE 

No component.

MASK_R 

R component mask.

MASK_I 

I component mask.

MASK_J 

J component mask.

MASK_K 

K component mask.

MASK_IJK 

Component mask for I, J and K (imaginary part)

MASK_ALL 

All components.

◆ PredefinedType

template<class DataType >
enum Murl::Math::Quaternion::PredefinedType

Enumeration of the predefined initialization types for constructing a Quaternion(PredefinedType type).

Enumerator
UNINITIALIZED 

Create an uninitialized instance.

IDENTITY 

Initialize with the identity {1, 0, 0, 0}.

Constructor & Destructor Documentation

◆ Quaternion() [1/6]

template<class DataType >
Murl::Math::Quaternion< DataType >::Quaternion ( DataType  vr,
DataType  vi,
DataType  vj,
DataType  vk 
)
inline

Constructor to initialize a quaternion with given component values.

Parameters
vrThe r component.
viThe i component.
vjThe j component.
vkThe k component.

◆ Quaternion() [2/6]

template<class DataType >
Murl::Math::Quaternion< DataType >::Quaternion ( const Vector< DataType > &  v)
inline

Constructor to initialize a quaternion from a given 4-vector containing a normalized rotation axis in its x,y and z components, and a rotation angle in its w component.

Parameters
vThe vector.

References Murl::Math::Cos(), Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, and Murl::Math::Sin().

◆ Quaternion() [3/6]

template<class DataType >
Murl::Math::Quaternion< DataType >::Quaternion ( DataType  angle,
const Vector< DataType > &  axis 
)
inline

Constructor to initialize a quaternion from a given rotation angle and a normalized axis vector.

Parameters
angleThe rotation angle.
axisThe normalized axis vector.

References Murl::Math::Cos(), Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, Murl::Math::Sin(), Murl::Math::Vector< DataType >::x, Murl::Math::Vector< DataType >::y, and Murl::Math::Vector< DataType >::z.

◆ Quaternion() [4/6]

template<class DataType >
Murl::Math::Quaternion< DataType >::Quaternion ( const Matrix< DataType > &  m)
inline

Constructor to initialize a quaternion from the rotation component of a given 4x4 matrix.

Parameters
mThe matrix.

References Murl::Math::Quaternion< DataType >::Set().

◆ Quaternion() [5/6]

template<class DataType >
Murl::Math::Quaternion< DataType >::Quaternion ( PredefinedType  type)
inline

◆ Quaternion() [6/6]

template<class DataType >
template<class DataType2 >
Murl::Math::Quaternion< DataType >::Quaternion ( const Quaternion< DataType2 > &  q)
inline

The copy constructor using a quaternion of different type.

Parameters
qThe quaternion to copy.

Member Function Documentation

◆ operator[]() [1/2]

template<class DataType >
const DataType& Murl::Math::Quaternion< DataType >::operator[] ( UInt32  index) const
inline

Get a const reference to one of the 4 component values.

Parameters
indexThe component index, see enum Component.
Returns
The component value const reference.

◆ operator[]() [2/2]

template<class DataType >
DataType& Murl::Math::Quaternion< DataType >::operator[] ( UInt32  index)
inline

Get a reference to one of the 4 component values.

Parameters
indexThe component index, see enum Component.
Returns
The component value reference.

◆ GetPointer() [1/2]

template<class DataType >
const DataType* Murl::Math::Quaternion< DataType >::GetPointer ( ) const
inline

Get a const pointer to the raw data.

Returns
Const pointer to the raw data.

References Murl::Math::Quaternion< DataType >::mComponents.

◆ GetPointer() [2/2]

template<class DataType >
DataType* Murl::Math::Quaternion< DataType >::GetPointer ( )
inline

Get a pointer to the raw data.

Returns
Pointer to the raw data.

References Murl::Math::Quaternion< DataType >::mComponents.

◆ Set() [1/3]

◆ operator=() [1/2]

template<class DataType >
Quaternion& Murl::Math::Quaternion< DataType >::operator= ( const Vector< DataType > &  v)
inline

Assignment operator to convert a 4D vector to a 4D quaternion.

Parameters
vThe vector to convert.
Returns
The object itself.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.

◆ operator=() [2/2]

template<class DataType >
Quaternion& Murl::Math::Quaternion< DataType >::operator= ( const Matrix< DataType > &  m)
inline

Assignment operator to convert a 4D matrix to a 4D quaternion.

Parameters
mThe matrix to convert.
Returns
The object itself.

References Murl::Math::Quaternion< DataType >::Set().

◆ operator+=()

template<class DataType >
Quaternion& Murl::Math::Quaternion< DataType >::operator+= ( const Quaternion< DataType > &  q)
inline

In-place addition operator.

Parameters
qThe quaternion to add.
Returns
The object itself.

References Murl::Math::Quaternion< DataType >::AddSelf().

◆ operator*=() [1/3]

template<class DataType >
Quaternion& Murl::Math::Quaternion< DataType >::operator*= ( const Quaternion< DataType > &  q)
inline

In-place subtraction operator.

Parameters
qThe quaternion to subtract.
Returns
The object itself.

References Murl::Math::Quaternion< DataType >::MultiplySelf().

◆ operator*=() [2/3]

template<class DataType >
Quaternion& Murl::Math::Quaternion< DataType >::operator*= ( const Vector< DataType > &  v)
inline

In-place quaternion-vector multiplication operator.

Parameters
vThe vector to multiply.
Returns
The object itself.

References Murl::Math::Quaternion< DataType >::MultiplySelf().

◆ operator*=() [3/3]

template<class DataType >
Quaternion& Murl::Math::Quaternion< DataType >::operator*= ( DataType  d)
inline

In-place multiplication operator (scaling).

Parameters
dThe value to multiply.
Returns
The object itself.

References Murl::Math::Quaternion< DataType >::MultiplySelf().

◆ operator+()

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::operator+ ( const Quaternion< DataType > &  rhs) const
inline

Addition operator.

Parameters
rhsThe right hand side quaternion.
Returns
The added quaternion.

References Murl::Math::Quaternion< DataType >::Add().

◆ operator*() [1/3]

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::operator* ( const Quaternion< DataType > &  rhs) const
inline

Quaternion-quaternion multiplication operator.

Parameters
rhsThe right hand side quaternion.
Returns
The multiplied quaternion.

References Murl::Math::Quaternion< DataType >::Multiply().

◆ operator*() [2/3]

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::operator* ( const Vector< DataType > &  rhs) const
inline

Quaternion-vector multiplication operator.

Parameters
rhsThe right hand side vector.
Returns
The multiplied quaternion.

References Murl::Math::Quaternion< DataType >::Multiply().

◆ operator*() [3/3]

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::operator* ( DataType  rhs) const
inline

Multiplication (scaling) operator.

Parameters
rhsThe right hand side value.
Returns
The multiplied quaternion.

References Murl::Math::Quaternion< DataType >::Multiply().

◆ Clear()

template<class DataType >
void Murl::Math::Quaternion< DataType >::Clear ( )
inline

Clear all components of the quaternion instance.

Set all components to default constructor of data type.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.

◆ Set() [2/3]

template<class DataType >
void Murl::Math::Quaternion< DataType >::Set ( const Quaternion< DataType > &  q)
inline

Copy the content of a source quaternion to the quaternion instance.

Parameters
qThe quaternion to copy from.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.

◆ Set() [3/3]

template<class DataType >
void Murl::Math::Quaternion< DataType >::Set ( DataType  vr,
DataType  vi,
DataType  vj,
DataType  vk 
)
inline

Set all components of the quaternion instance to a set of given component values.

Parameters
vrThe x-component value to set.
viThe y-component value to set.
vjThe z-component value to set.
vkThe w-component value to set.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.

◆ AddSelf()

template<class DataType >
void Murl::Math::Quaternion< DataType >::AddSelf ( const Quaternion< DataType > &  q)
inline

In-place addition.

Parameters
qThe quaternion to add.

References Murl::Math::Quaternion< DataType >::Add(), and Murl::Math::Quaternion< DataType >::Set().

Referenced by Murl::Math::Quaternion< DataType >::operator+=().

◆ MultiplySelf() [1/3]

template<class DataType >
void Murl::Math::Quaternion< DataType >::MultiplySelf ( const Quaternion< DataType > &  q)
inline

In-place Quaternion-quaternion multiplication.

Parameters
qThe quaternion to multiply.

References Murl::Math::Quaternion< DataType >::Multiply(), and Murl::Math::Quaternion< DataType >::Set().

Referenced by Murl::Math::Quaternion< DataType >::operator*=().

◆ MultiplySelf() [2/3]

template<class DataType >
void Murl::Math::Quaternion< DataType >::MultiplySelf ( const Vector< DataType > &  v)
inline

In-place Quaternion-vector multiplication.

Parameters
vThe vector to multiply.

References Murl::Math::Quaternion< DataType >::Multiply(), and Murl::Math::Quaternion< DataType >::Set().

◆ MultiplySelf() [3/3]

template<class DataType >
void Murl::Math::Quaternion< DataType >::MultiplySelf ( DataType  d)
inline

In-place multiplication (scaling).

Parameters
dThe value to multiply.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.

◆ Invert()

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::Invert ( ) const
inline

Get the inverse of a quaternion.

This only works for normalized quaternions.

Returns
The inverted quaternion.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, and Murl::Math::Quaternion< DataType >::r.

Referenced by Murl::Math::Quaternion< DataType >::InvertSelf().

◆ Add()

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::Add ( const Quaternion< DataType > &  q) const
inline

◆ Multiply() [1/3]

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::Multiply ( const Quaternion< DataType > &  q) const
inline

◆ Multiply() [2/3]

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::Multiply ( const Vector< DataType > &  v) const
inline

Get the multiplication with a vector.

Parameters
vThe vector to multiply.
Returns
The multiplied quaternion.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, and Murl::Math::Quaternion< DataType >::r.

◆ Multiply() [3/3]

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::Multiply ( DataType  d) const
inline

Get the multiplication (scaling).

Parameters
dThe value to multiply.
Returns
The multiplied quaternion.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, and Murl::Math::Quaternion< DataType >::r.

◆ Normalize()

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::Normalize ( ) const
inline

◆ Interpolate()

template<class DataType >
Quaternion Murl::Math::Quaternion< DataType >::Interpolate ( const Quaternion< DataType > &  q,
DataType  t,
Bool  spherical 
) const
inline

Interpolate between this instance and a second quaternion.

For t=0.0, the result equals the first quaternion, and for t=1.0 the second one.

Parameters
qThe quaternion to interpolate to.
tThe interpolation factor.
sphericalIf true, a spherical interpolation is applied. If false, nterpolation is performed in a linear way.
Returns
The interpolated quaternion.

References Murl::Math::ArcCos(), Murl::Math::Clamp(), Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, Murl::Math::Quaternion< DataType >::r, and Murl::Math::Sin().

◆ IsEqual() [1/2]

template<class DataType >
Bool Murl::Math::Quaternion< DataType >::IsEqual ( const Quaternion< DataType > &  q) const
inline

Check if the quaternion instance is equal to a given second quaternion.

Compares all values within the default epsilon range Limits::Epsilon().

Parameters
qThe quaternion to compare.
Returns
true if equal to the compared quaternion.

◆ IsEqual() [2/2]

template<class DataType >
Bool Murl::Math::Quaternion< DataType >::IsEqual ( const Quaternion< DataType > &  q,
DataType  epsilon 
) const
inline

Check if the quaternion instance is equal to a given second quaternion.

Compares all values within a given epsilon range.

Parameters
qThe quaternion to compare.
epsilonThe epsilon to compare.
Returns
true if equal to the compared quaternion.

References Murl::Math::Abs(), Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.

◆ ToString()

template<class DataType >
String Murl::Math::Quaternion< DataType >::ToString ( ) const
inline

Get the string representation of the object.

Returns
The string representation of the object.

References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, and Murl::Util::PrintToString().

◆ GetCount()

template<class DataType >
SInt32 Murl::Math::Quaternion< DataType >::GetCount ( ) const
inline

Get the number of elements in the object.

Returns
The number of elements in the object.

References Murl::Math::Quaternion< DataType >::NUM_COMPONENTS.

Friends And Related Function Documentation

◆ operator==

template<class DataType >
bool operator== ( const Quaternion< DataType > &  lhs,
const Quaternion< DataType > &  rhs 
)
friend

Equal to comparison operator.

Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Quaternion> class. To compare within an epsilon range use Quaternion::IsEqual().

Parameters
lhsThe left hand side quaternion to compare.
rhsThe right hand side quaternion to compare.
Returns
true if all components are exactly the same.

◆ operator!=

template<class DataType >
bool operator!= ( const Quaternion< DataType > &  lhs,
const Quaternion< DataType > &  rhs 
)
friend

Not equal to comparison operator.

Performs a test without an epsilon range, which can be used for detecting changes i.e. DoubleBuffer<Quaternion> class. To compare within an epsilon range use Quaternion::IsEqual().

Parameters
lhsThe left hand side quaternion to compare.
rhsThe right hand side quaternion to compare.
Returns
true if all components are not exactly the same.

The documentation for this class was generated from the following files:
  • murl_app_types.h
  • murl_math_quaternion.h


Copyright © 2011-2024 Spraylight GmbH.