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... | |
Quaternion & | operator= (const Vector< DataType > &v) |
Assignment operator to convert a 4D vector to a 4D quaternion. More... | |
Quaternion & | operator= (const Matrix< DataType > &m) |
Assignment operator to convert a 4D matrix to a 4D quaternion. More... | |
Quaternion & | operator+= (const Quaternion &q) |
In-place addition operator. More... | |
Quaternion & | operator*= (const Quaternion &q) |
In-place subtraction operator. More... | |
Quaternion & | operator*= (const Vector< DataType > &v) |
In-place quaternion-vector multiplication operator. More... | |
Quaternion & | operator*= (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
enum Murl::Math::Quaternion::Component |
◆ ComponentMask
enum Murl::Math::Quaternion::ComponentMask |
◆ PredefinedType
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]
|
inline |
Constructor to initialize a quaternion with given component values.
- Parameters
-
vr The r component. vi The i component. vj The j component. vk The k component.
◆ Quaternion() [2/6]
|
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
-
v The 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]
|
inline |
Constructor to initialize a quaternion from a given rotation angle and a normalized axis vector.
- Parameters
-
angle The rotation angle. axis The 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]
|
inline |
Constructor to initialize a quaternion from the rotation component of a given 4x4 matrix.
- Parameters
-
m The matrix.
References Murl::Math::Quaternion< DataType >::Set().
◆ Quaternion() [5/6]
|
inline |
Constructor to create a quaternion from a predefined type.
- Parameters
-
type The predefined type.
References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::IDENTITY, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, and Murl::Math::Quaternion< DataType >::UNINITIALIZED.
◆ Quaternion() [6/6]
|
inline |
The copy constructor using a quaternion of different type.
- Parameters
-
q The quaternion to copy.
Member Function Documentation
◆ operator[]() [1/2]
|
inline |
Get a const reference to one of the 4 component values.
- Parameters
-
index The component index, see enum Component.
- Returns
- The component value const reference.
◆ operator[]() [2/2]
|
inline |
Get a reference to one of the 4 component values.
- Parameters
-
index The component index, see enum Component.
- Returns
- The component value reference.
◆ GetPointer() [1/2]
|
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]
|
inline |
Get a pointer to the raw data.
- Returns
- Pointer to the raw data.
References Murl::Math::Quaternion< DataType >::mComponents.
◆ Set() [1/3]
|
inline |
Set the quaternion from the rotation component of a given 4D matrix.
- Parameters
-
m The input matrix.
References Murl::Math::Matrix< DataType >::GetXX(), Murl::Math::Matrix< DataType >::GetXY(), Murl::Math::Matrix< DataType >::GetXZ(), Murl::Math::Matrix< DataType >::GetYX(), Murl::Math::Matrix< DataType >::GetYY(), Murl::Math::Matrix< DataType >::GetYZ(), Murl::Math::Matrix< DataType >::GetZX(), Murl::Math::Matrix< DataType >::GetZY(), Murl::Math::Matrix< DataType >::GetZZ(), Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, Murl::Math::Max(), and Murl::Math::Sqrt().
Referenced by Murl::Math::Quaternion< DataType >::AddSelf(), Murl::Math::Quaternion< DataType >::InvertSelf(), Murl::Math::Quaternion< DataType >::MultiplySelf(), Murl::Math::Quaternion< DataType >::operator=(), and Murl::Math::Quaternion< DataType >::Quaternion().
◆ operator=() [1/2]
|
inline |
Assignment operator to convert a 4D vector to a 4D quaternion.
- Parameters
-
v The 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]
|
inline |
Assignment operator to convert a 4D matrix to a 4D quaternion.
- Parameters
-
m The matrix to convert.
- Returns
- The object itself.
References Murl::Math::Quaternion< DataType >::Set().
◆ operator+=()
|
inline |
In-place addition operator.
- Parameters
-
q The quaternion to add.
- Returns
- The object itself.
References Murl::Math::Quaternion< DataType >::AddSelf().
◆ operator*=() [1/3]
|
inline |
In-place subtraction operator.
- Parameters
-
q The quaternion to subtract.
- Returns
- The object itself.
References Murl::Math::Quaternion< DataType >::MultiplySelf().
◆ operator*=() [2/3]
|
inline |
In-place quaternion-vector multiplication operator.
- Parameters
-
v The vector to multiply.
- Returns
- The object itself.
References Murl::Math::Quaternion< DataType >::MultiplySelf().
◆ operator*=() [3/3]
|
inline |
In-place multiplication operator (scaling).
- Parameters
-
d The value to multiply.
- Returns
- The object itself.
References Murl::Math::Quaternion< DataType >::MultiplySelf().
◆ operator+()
|
inline |
Addition operator.
- Parameters
-
rhs The right hand side quaternion.
- Returns
- The added quaternion.
References Murl::Math::Quaternion< DataType >::Add().
◆ operator*() [1/3]
|
inline |
Quaternion-quaternion multiplication operator.
- Parameters
-
rhs The right hand side quaternion.
- Returns
- The multiplied quaternion.
References Murl::Math::Quaternion< DataType >::Multiply().
◆ operator*() [2/3]
|
inline |
Quaternion-vector multiplication operator.
- Parameters
-
rhs The right hand side vector.
- Returns
- The multiplied quaternion.
References Murl::Math::Quaternion< DataType >::Multiply().
◆ operator*() [3/3]
|
inline |
Multiplication (scaling) operator.
- Parameters
-
rhs The right hand side value.
- Returns
- The multiplied quaternion.
References Murl::Math::Quaternion< DataType >::Multiply().
◆ 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]
|
inline |
Copy the content of a source quaternion to the quaternion instance.
- Parameters
-
q The quaternion to copy from.
References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.
◆ Set() [3/3]
|
inline |
Set all components of the quaternion instance to a set of given component values.
- Parameters
-
vr The x-component value to set. vi The y-component value to set. vj The z-component value to set. vk The w-component value to set.
References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.
◆ AddSelf()
|
inline |
In-place addition.
- Parameters
-
q The 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]
|
inline |
In-place Quaternion-quaternion multiplication.
- Parameters
-
q The 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]
|
inline |
In-place Quaternion-vector multiplication.
- Parameters
-
v The vector to multiply.
References Murl::Math::Quaternion< DataType >::Multiply(), and Murl::Math::Quaternion< DataType >::Set().
◆ MultiplySelf() [3/3]
|
inline |
In-place multiplication (scaling).
- Parameters
-
d The value to multiply.
References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, and Murl::Math::Quaternion< DataType >::k.
◆ Invert()
|
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()
|
inline |
Get the addition of a quaternion.
- Parameters
-
q The quaternion to add.
- Returns
- The added 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 >::AddSelf(), and Murl::Math::Quaternion< DataType >::operator+().
◆ Multiply() [1/3]
|
inline |
Get the multiplication with a quaternion.
- Parameters
-
q The quaternion 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.
Referenced by Murl::Math::Quaternion< DataType >::MultiplySelf(), and Murl::Math::Quaternion< DataType >::operator*().
◆ Multiply() [2/3]
|
inline |
Get the multiplication with a vector.
- Parameters
-
v The 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]
|
inline |
Get the multiplication (scaling).
- Parameters
-
d The 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()
|
inline |
Get the normalization of the quaternion instance.
- Returns
- The normalized quaternion.
References Murl::Math::Quaternion< DataType >::i, Murl::Math::Quaternion< DataType >::j, Murl::Math::Quaternion< DataType >::k, Murl::Math::Quaternion< DataType >::r, and Murl::Math::Sqrt().
◆ Interpolate()
|
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
-
q The quaternion to interpolate to. t The interpolation factor. spherical If 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]
|
inline |
Check if the quaternion instance is equal to a given second quaternion.
Compares all values within the default epsilon range Limits::Epsilon().
- Parameters
-
q The quaternion to compare.
- Returns
- true if equal to the compared quaternion.
◆ IsEqual() [2/2]
|
inline |
Check if the quaternion instance is equal to a given second quaternion.
Compares all values within a given epsilon range.
- Parameters
-
q The quaternion to compare. epsilon The 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()
|
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()
|
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==
|
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
-
lhs The left hand side quaternion to compare. rhs The right hand side quaternion to compare.
- Returns
- true if all components are exactly the same.
◆ operator!=
|
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
-
lhs The left hand side quaternion to compare. rhs The 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