3es  0.7
tes::Quaternion< T > Class Template Reference

A 4D rotational quaternion class. More...

#include <3esquaternion.h>

Public Member Functions

 Quaternion ()
 Default constructor: undefined initialisation behaviour.
 
 Quaternion (bool)
 The identity constructor. More...
 
 Quaternion (const Quaternion< T > &other)
 Copy constructor. More...
 
template<typename Q >
 Quaternion (const Quaternion< Q > &other)
 Copy constructor from a different numeric type. More...
 
 Quaternion (const T &x, const T &y, const T &z, const T &w)
 Per coordinate initialisation. More...
 
 Quaternion (const Vector3< T > &v, const T &w)
 Vector plus scalar initialisation. More...
 
 Quaternion (const T *array4)
 Initialisation from a array of at least length 4. More...
 
 Quaternion (const Vector3< T > &from, const Vector3< T > &to)
 Create the quaternion rotation transforming from => to. More...
 
T & operator[] (int index)
 Index operator. More...
 
const T & operator[] (int index) const
 
Quaternion< T > & operator= (const Quaternion< T > &other)
 Simple assignment operator. More...
 
template<typename Q >
Quaternion< T > & operator= (const Quaternion< Q > &other)
 Simple assignment operator from a different numeric type. More...
 
bool operator== (const Quaternion< T > &other) const
 Exact equality operator. More...
 
bool operator!= (const Quaternion< T > &other) const
 Exact inequality operator. More...
 
bool isEqual (const Quaternion< T > &other, const T &epsilon=Vector3< T >::Epsilon)
 Equality test with error. More...
 
bool isIdentity ()
 Checks if this quaternion is exactly identity. More...
 
void getAxisAngle (Vector3< T > &axis, T &angle) const
 Converts this quaternion into a axis of rotation and the rotation angle around that axis (radians). More...
 
Quaternion< T > & setAxisAngle (const Vector3< T > &axis, const T &angle)
 Sets this quaternion from an axis of rotation and the angle of rotation about that axis (radians). More...
 
Quaternion< T > & invert ()
 Inverts this quaternion, making the counter rotation. More...
 
Quaternion< T > inverse () const
 Calculates and returns the inverse of this quaternion. More...
 
Quaternion< T > & conjugate ()
 Sets this quaternion to its conjugate. More...
 
Quaternion< T > conjugated () const
 Calculates and returns the conjugate of this quaternion. More...
 
normalise (const T &epsilon=Vector3< T >::Epsilon)
 Attempts to normalise this quaternion. More...
 
Quaternion< T > normalised (const T &epsilon=Vector3< T >::Epsilon) const
 Returns a normalised copy of this quaternion. More...
 
magnitude () const
 Returns the magnitude of this quaternion.
 
magnitudeSquared () const
 Returns the magnitude squared of this quaternion.
 
dot (const Quaternion< T > other) const
 Calculates the dot product of this and other.
 
Vector3< T > transform (const Vector3< T > &v) const
 Transforms v by this quaternion rotation. More...
 
Quaternion< T > & multiply (const T &scalar)
 Multiply all components of this quaternion by a scalar. More...
 
Quaternion< T > operator*= (const Quaternion< T > &other)
 
Quaternion< T > operator*= (const T &scalar)
 

Static Public Member Functions

static Quaternion< T > slerp (const Quaternion< T > &from, const Quaternion< T > &to, const T &t)
 Performs a spherical linear interpolation of one quaternion to another. More...
 

Public Attributes

union {
   struct {
      T   x
 Direct data member access.
 
      T   y
 
      T   z
 
      T   w
 
   } 
 
   T   q [4]
 Array representation of the vector members.
 
}; 
 

Static Public Attributes

static const Quaternion< T > identity
 The identity quaternion (0, 0, 0, 1).
 

Detailed Description

template<typename T>
class tes::Quaternion< T >

A 4D rotational quaternion class.

Constructor & Destructor Documentation

◆ Quaternion() [1/7]

template<typename T>
tes::Quaternion< T >::Quaternion ( bool  )
inline

The identity constructor.

The boolean parameter is ignored, being used only for overloading. General usage is to set it to true.

◆ Quaternion() [2/7]

template<typename T>
tes::Quaternion< T >::Quaternion ( const Quaternion< T > &  other)
inline

Copy constructor.

Parameters
otherVector to copy the value of.

◆ Quaternion() [3/7]

template<typename T>
template<typename Q >
tes::Quaternion< T >::Quaternion ( const Quaternion< Q > &  other)
inline

Copy constructor from a different numeric type.

Parameters
otherVector to copy the value of.

◆ Quaternion() [4/7]

template<typename T>
tes::Quaternion< T >::Quaternion ( const T &  x,
const T &  y,
const T &  z,
const T &  w 
)
inline

Per coordinate initialisation.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
wThe w coordinate.

◆ Quaternion() [5/7]

template<typename T>
tes::Quaternion< T >::Quaternion ( const Vector3< T > &  v,
const T &  w 
)
inline

Vector plus scalar initialisation.

Parameters
vValues for x, y and z.
wThe w coordinate.

◆ Quaternion() [6/7]

template<typename T>
tes::Quaternion< T >::Quaternion ( const T *  array4)
inline

Initialisation from a array of at least length 4.

No bounds checking is performed.

Parameters
array4An array of at least length 4. Copies elements (0, 1, 2, 3).

◆ Quaternion() [7/7]

template<typename T>
tes::Quaternion< T >::Quaternion ( const Vector3< T > &  from,
const Vector3< T > &  to 
)

Create the quaternion rotation transforming from => to.

Parameters
fromStarting vector.
toTarget vector.

Member Function Documentation

◆ conjugate()

template<typename T>
Quaternion<T>& tes::Quaternion< T >::conjugate ( )

Sets this quaternion to its conjugate.

The conjugate is the same quaternion with x, y, z values negated.

Returns
This after the conjugate calculation.

Referenced by tes::Quaternion< float >::operator=().

◆ conjugated()

template<typename T>
Quaternion<T> tes::Quaternion< T >::conjugated ( ) const

Calculates and returns the conjugate of this quaternion.

The conjugate is the same quaternion with x, y, z values negated.

Returns
This quaternion's conjugate.

Referenced by tes::Quaternion< float >::operator=().

◆ getAxisAngle()

template<typename T>
void tes::Quaternion< T >::getAxisAngle ( Vector3< T > &  axis,
T &  angle 
) const

Converts this quaternion into a axis of rotation and the rotation angle around that axis (radians).

Parameters
[out]axisSet to the axis of rotation. Set to (0, 0, 1) if this quaternion is identity or near zero length.
[out]angleSet to the rotation angle (radians). Zero if this quaternion is identity.

Referenced by tes::Quaternion< float >::operator=().

◆ inverse()

template<typename T>
Quaternion<T> tes::Quaternion< T >::inverse ( ) const

Calculates and returns the inverse of this quaternion.

Returns
The inverse of this quaternion.

Referenced by tes::Quaternion< float >::operator=().

◆ invert()

template<typename T>
Quaternion<T>& tes::Quaternion< T >::invert ( )

Inverts this quaternion, making the counter rotation.

Returns
This after inversion.

Referenced by tes::Quaternion< float >::operator=().

◆ isEqual()

template<typename T>
bool tes::Quaternion< T >::isEqual ( const Quaternion< T > &  other,
const T &  epsilon = Vector3< T >::Epsilon 
)

Equality test with error.

Defaults to using Epsilon.

The vectors are considered equal of each individual component is within +/- epsilon of it's corresponding component in other.

Parameters
otherThe vector to compare to.
epsilonThe error tolerance.
Returns
True this and other are equal with epsilon.

Referenced by tes::Quaternion< float >::operator=().

◆ isIdentity()

template<typename T>
bool tes::Quaternion< T >::isIdentity ( )

Checks if this quaternion is exactly identity.

Returns
True if this is exactly the identity quaternion.

Referenced by tes::Quaternion< float >::operator=().

◆ multiply()

template<typename T>
Quaternion<T>& tes::Quaternion< T >::multiply ( const T &  scalar)

Multiply all components of this quaternion by a scalar.

Returns
This after the multiplication.

Referenced by tes::Quaternion< float >::operator=().

◆ normalise()

template<typename T>
T tes::Quaternion< T >::normalise ( const T &  epsilon = Vector3< T >::Epsilon)

Attempts to normalise this quaternion.

Normalisation fails if the length of this quaternion is less than or equal to epsilon. In this case, the quaternion becomes identity.

Returns
The magnitude of this quaternion before normalisation or zero if normalisation failed.

Referenced by tes::Quaternion< float >::operator=().

◆ normalised()

template<typename T>
Quaternion<T> tes::Quaternion< T >::normalised ( const T &  epsilon = Vector3< T >::Epsilon) const

Returns a normalised copy of this quaternion.

Normalisation fails if the length of this quaternion is less than or equal to epsilon.

Returns
A normalised copy of this quaternion, or a zero quaternion if if normalisation failed.

Referenced by tes::Quaternion< float >::operator=().

◆ operator!=()

template<typename T>
bool tes::Quaternion< T >::operator!= ( const Quaternion< T > &  other) const

Exact inequality operator.

Compares each component with the same operator.

Parameters
otherThe vector to compare to.
Returns
True if this is not exactly equal to other.

Referenced by tes::Quaternion< float >::operator=().

◆ operator=() [1/2]

template<typename T>
Quaternion<T>& tes::Quaternion< T >::operator= ( const Quaternion< T > &  other)
inline

Simple assignment operator.

Parameters
otherVector to copy the value of.
Returns
This.

◆ operator=() [2/2]

template<typename T>
template<typename Q >
Quaternion<T>& tes::Quaternion< T >::operator= ( const Quaternion< Q > &  other)
inline

Simple assignment operator from a different numeric type.

Parameters
otherVector to copy the value of.
Returns
This.

◆ operator==()

template<typename T>
bool tes::Quaternion< T >::operator== ( const Quaternion< T > &  other) const

Exact equality operator.

Compares each component with the same operator.

Parameters
otherThe vector to compare to.
Returns
True if this is exactly equal to other.

Referenced by tes::Quaternion< float >::operator=().

◆ operator[]() [1/2]

template<typename T>
T& tes::Quaternion< T >::operator[] ( int  index)
inline

Index operator.

Not bounds checked.

Parameters
indexAccess coordinates by index; 0 = x, 1 = y, 2 = z.
Returns
The coordinate value.

◆ operator[]() [2/2]

template<typename T>
const T& tes::Quaternion< T >::operator[] ( int  index) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ setAxisAngle()

template<typename T>
Quaternion<T>& tes::Quaternion< T >::setAxisAngle ( const Vector3< T > &  axis,
const T &  angle 
)

Sets this quaternion from an axis of rotation and the angle of rotation about that axis (radians).

Parameters
axisThe axis of rotation.
angleThe rotation angle (radians).

Referenced by tes::Quaternion< float >::operator=(), tes::Capsule::setAxis(), tes::Cylinder::setAxis(), tes::Cone::setDirection(), tes::Arrow::setDirection(), and tes::Text3D::Text3D().

◆ slerp()

template<typename T>
static Quaternion<T> tes::Quaternion< T >::slerp ( const Quaternion< T > &  from,
const Quaternion< T > &  to,
const T &  t 
)
static

Performs a spherical linear interpolation of one quaternion to another.

Parameters
fromThe quaternion rotation to interpolate from.
toThe quaternion rotation to interpolate to.
tThe interpolation "time", [0, 1].
Returns
The interpolated result.

Referenced by tes::Quaternion< float >::operator=().

◆ transform()

template<typename T>
Vector3<T> tes::Quaternion< T >::transform ( const Vector3< T > &  v) const

Transforms v by this quaternion rotation.

Returns
The transformed vector.

Referenced by tes::Quaternion< float >::operator=().


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