Ocean
Ocean::QuaternionT< T > Class Template Reference

This class implements a unit quaternion rotation. More...

Inheritance diagram for Ocean::QuaternionT< T >:

Public Types

typedef T Type
 Definition of the used data type. More...
 

Public Member Functions

 QuaternionT ()=default
 Creates a new quaternion with default values, representation an identity rotation. More...
 
 QuaternionT (const bool toIdentity)
 Creates a new quaternion with either default values (representation an identity rotation) or an invalid rotation. More...
 
template<typename U >
 QuaternionT (const QuaternionT< U > &quaternion)
 Copies a quaternion with different element data type than T. More...
 
 QuaternionT (const T w, const T x, const T y, const T z)
 Creates a new quaternion by four given values. More...
 
 QuaternionT (const VectorT3< T > &axis, const T angle)
 Creates a new quaternion by a given axis and rotation angle. More...
 
 QuaternionT (const VectorT3< T > &reference, const VectorT3< T > &offset)
 Creates a quaternion object based on two given unit vectors. More...
 
 QuaternionT (const RotationT< T > &rotation)
 Creates a new quaternion by a given angle-axis rotation. More...
 
 QuaternionT (const EulerT< T > &euler)
 Creates a new quaternion by a given Euler rotation. More...
 
 QuaternionT (const SquareMatrixT3< T > &matrix)
 Creates a new quaternion by a given 3x3 rotation matrix. More...
 
 QuaternionT (const HomogenousMatrixT4< T > &transformation)
 Creates a new quaternion by a given 4x4 homogeneous transformation matrix. More...
 
 QuaternionT (const VectorT4< T > &vector)
 Creates a new quaternion by a 4D vector. More...
 
 QuaternionT (const T *arrayValue)
 Creates a new quaternion by an array with at least four elements. More...
 
QuaternionT< T > normalized () const
 Returns the normalized quaternion. More...
 
bool normalize ()
 Normalizes the quaternion in place. More...
 
bool normalize (QuaternionT< T > &normalizedQuaternion) const
 Normalizes the quaternion and returns the result as parameter. More...
 
QuaternionT< T > inverted () const
 Returns the inverted quaternion. More...
 
bool invert ()
 Inverts this quaternion in place. More...
 
bool invert (QuaternionT< T > &invertedQuaternion) const
 Inverts this quaternion and returns the result as parameter. More...
 
QuaternionT< T > conjugate () const
 Returns the conjugate of this quaternion. More...
 
norm () const
 Returns the norm of this quaternion. More...
 
sqr () const
 Returns the square of the quaternion norm. More...
 
dot (const QuaternionT< T > &quaternion) const
 Returns the dot product between this quaternion and a second quaternion. More...
 
angle () const
 Returns the rotation angle defined by the quaternion. More...
 
angle (const QuaternionT< T > &quaternion) const
 Returns the angle between two quaternion rotations. More...
 
smallestAngle (const QuaternionT< T > &quaternion) const
 Returns the smallest angle between two quaternion rotations. More...
 
cos2 (const QuaternionT< T > &quaternion) const
 Returns the cosine value of the half angle between two quaternion rotations. More...
 
QuaternionT< T > slerp (const QuaternionT< T > &quaternion, T factor) const
 Spherical linear interpolation between two quaternions. More...
 
bool isValid () const
 Returns whether this quaternion is a valid unit quaternion. More...
 
const T & w () const
 Returns the w value of the quaternion. More...
 
T & w ()
 Returns the w value of the quaternion. More...
 
const T & x () const
 Returns the x value of the quaternion. More...
 
T & x ()
 Returns the x value of the quaternion. More...
 
const T & y () const
 Returns the y value of the quaternion. More...
 
T & y ()
 Returns the y value of the quaternion. More...
 
const T & z () const
 Returns the z value of the quaternion. More...
 
T & z ()
 Returns the z value of the quaternion. More...
 
bool isEqual (const QuaternionT< T > &quaternion, const T eps) const
 Returns whether two quaternions are equal up to a specified epsilon. More...
 
bool operator== (const QuaternionT< T > &right) const
 Returns whether two quaternions are identical up to a small epsilon. More...
 
bool operator!= (const QuaternionT< T > &right) const
 Returns whether two quaternions are not identical up to a small epsilon. More...
 
QuaternionT< T > operator* (const QuaternionT< T > &right) const
 Combines two quaternion to a new combined rotation. More...
 
QuaternionT< T > operator* (const RotationT< T > &right) const
 Combines a angle-axis rotation with this quaternion. More...
 
VectorT3< T > operator* (const VectorT3< T > &vector) const
 Rotates a 3D vector by this quaternion. More...
 
QuaternionT< T > & operator*= (const QuaternionT< T > &right)
 Combines and assigns two quaternions. More...
 
QuaternionT< T > & operator*= (const RotationT< T > &right)
 Combines and assigns a quaternion with a rotation. More...
 
operator[] (const unsigned int index) const
 Element operator. More...
 
T & operator[] (const unsigned int index)
 Element operator. More...
 
operator() (const unsigned int index) const
 Element operator. More...
 
T & operator() (const unsigned int index)
 Element operator. More...
 
const T * operator() () const
 Access operator. More...
 
T * operator() ()
 Access operator. More...
 

Protected Attributes

values_ [4] = {T(1), T(0), T(0), T(0)}
 The four values of the quaternion. More...
 

Detailed Description

template<typename T>
class Ocean::QuaternionT< T >

This class implements a unit quaternion rotation.

A quaternion is defined by four values:

w + xi + yj + zk
with
i * i = -1, j * j = -1, k * k = -1

The elements are stored in the following order: w, x, y, z

Template Parameters
TData type used to represent the quaternion values
See also
Quaternion, QuaternionF, QuaternionD, Rotation, Euler, SquareMatrix3, ExponentialMap.

Member Typedef Documentation

◆ Type

template<typename T >
typedef T Ocean::QuaternionT< T >::Type

Definition of the used data type.

Constructor & Destructor Documentation

◆ QuaternionT() [1/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( )
default

Creates a new quaternion with default values, representation an identity rotation.

◆ QuaternionT() [2/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const bool  toIdentity)
explicit

Creates a new quaternion with either default values (representation an identity rotation) or an invalid rotation.

Parameters
toIdentityTrue, to create an identity rotation; False, to created an invalid rotation

◆ QuaternionT() [3/12]

template<typename T >
template<typename U >
Ocean::QuaternionT< T >::QuaternionT ( const QuaternionT< U > &  quaternion)
inlineexplicit

Copies a quaternion with different element data type than T.

Parameters
quaternionThe quaternion object to be copied
Template Parameters
UThe element data type of the given quaternion

◆ QuaternionT() [4/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const T  w,
const T  x,
const T  y,
const T  z 
)

Creates a new quaternion by four given values.

Parameters
wW value of the quaternion, with range (-infinity, infinity)
xX value of the quaternion, with range (-infinity, infinity)
yY value of the quaternion, with range (-infinity, infinity)
zZ value of the quaternion, with range (-infinity, infinity)

◆ QuaternionT() [5/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const VectorT3< T > &  axis,
const T  angle 
)

Creates a new quaternion by a given axis and rotation angle.

Parameters
axisThe axis of the angle-axis rotation with unit length
angleThe angle of the angle-axis rotation in radian, with range (-infinity, infinity), however will be converted to the range [0.0, 2 * PI)

◆ QuaternionT() [6/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const VectorT3< T > &  reference,
const VectorT3< T > &  offset 
)

Creates a quaternion object based on two given unit vectors.

The resulting rotation defines a transformation that rotates that reference vector into the offset vector: Quaternion(reference, offset) = offset_Q_reference.
The following equation holds:

offset = Quaternion(reference, offset) * reference.
Parameters
referenceThe reference vector, with length 1
offsetThe offset vector, with length 1

◆ QuaternionT() [7/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const RotationT< T > &  rotation)
explicit

Creates a new quaternion by a given angle-axis rotation.

Parameters
rotationThe rotation to create the quaternion from, must be valid

◆ QuaternionT() [8/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const EulerT< T > &  euler)
explicit

Creates a new quaternion by a given Euler rotation.

Parameters
eulerRotation to create the quaternion from, must be valid

◆ QuaternionT() [9/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const SquareMatrixT3< T > &  matrix)
explicit

Creates a new quaternion by a given 3x3 rotation matrix.

Parameters
matrixRotation matrix to create the quaternion from, with determinant 1

◆ QuaternionT() [10/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const HomogenousMatrixT4< T > &  transformation)
explicit

Creates a new quaternion by a given 4x4 homogeneous transformation matrix.

Parameters
transformationThe transformation matrix to create the quaternion from

◆ QuaternionT() [11/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const VectorT4< T > &  vector)
explicit

Creates a new quaternion by a 4D vector.

Parameters
vectorThe vector holding the four quaternion parameter

◆ QuaternionT() [12/12]

template<typename T >
Ocean::QuaternionT< T >::QuaternionT ( const T *  arrayValue)
explicit

Creates a new quaternion by an array with at least four elements.

Parameters
arrayValueArray with elements, must be valid

Member Function Documentation

◆ angle() [1/2]

template<typename T >
T Ocean::QuaternionT< T >::angle

Returns the rotation angle defined by the quaternion.

This angle is calculated based on the real part of the quaternion.
Beware: Ensure that this quaternion is valid.

Returns
Rotation angle in radian, with range [0, 2PI), 0 in case of an invalid quaternion

◆ angle() [2/2]

template<typename T >
T Ocean::QuaternionT< T >::angle ( const QuaternionT< T > &  quaternion) const

Returns the angle between two quaternion rotations.

This function may return angles larger than PI. Beware: Ensure that this quaternion is valid.

Parameters
quaternionSecond quaternion for angle determination, must be valid
Returns
Rotation angle in radian, with range [0, 2PI), 0 in case of an invalid quaternion
See also
smallestAngle().

◆ conjugate()

template<typename T >
QuaternionT< T > Ocean::QuaternionT< T >::conjugate

Returns the conjugate of this quaternion.

The conjugated quaternion is defined as: (w - xi - yj - zk)

Returns
Conjugate quaternion

◆ cos2()

template<typename T >
T Ocean::QuaternionT< T >::cos2 ( const QuaternionT< T > &  quaternion) const

Returns the cosine value of the half angle between two quaternion rotations.

To determine whether two quaternion rotations have a lesser angle offset than 30 degrees
this cos2 value must be larger than the cosine of 15 degrees.
Beware: Ensure that this quaternion is valid.

Parameters
quaternionSecond quaternion for value determination, must be valid
Returns
Cosine value of the half angle

◆ dot()

template<typename T >
T Ocean::QuaternionT< T >::dot ( const QuaternionT< T > &  quaternion) const

Returns the dot product between this quaternion and a second quaternion.

The function actually returns: w0 * w1 + x0 * x1 + y0 * y1 + z0 * z1, with quaternions (w0, x0, y0, z0) and (w1, x1, y1, z1).

Parameters
quaternionThe second quaternion for dot product calculation
Returns
The dot product between both quaternions

◆ invert() [1/2]

template<typename T >
bool Ocean::QuaternionT< T >::invert

Inverts this quaternion in place.

Returns
True, if the quaternion is not singular and could be inverted.
See also
inverted().

◆ invert() [2/2]

template<typename T >
bool Ocean::QuaternionT< T >::invert ( QuaternionT< T > &  invertedQuaternion) const

Inverts this quaternion and returns the result as parameter.

Parameters
invertedQuaternionThe resulting inverted quaternion
Returns
True, if the quaternion is not singular and could be inverted.
See also
inverted().

◆ inverted()

template<typename T >
QuaternionT< T > Ocean::QuaternionT< T >::inverted

Returns the inverted quaternion.

Beware: This function does not throw an exception if the quaternion is singular and cannot be inverted.
Thus ensure that the quaternion is valid before calling this function.
In case, this quaternion is not valid, a default quaternion will be returned.

Returns
Inverted quaternion
See also
isValid(), invert().

◆ isEqual()

template<typename T >
bool Ocean::QuaternionT< T >::isEqual ( const QuaternionT< T > &  quaternion,
const T  eps 
) const
inline

Returns whether two quaternions are equal up to a specified epsilon.

Parameters
quaternionSecond quaternion to compare
epsThe epsilon to be used, with range [0, infinity)
Returns
True, if so

◆ isValid()

template<typename T >
bool Ocean::QuaternionT< T >::isValid

Returns whether this quaternion is a valid unit quaternion.

Returns
True, if so

◆ norm()

template<typename T >
T Ocean::QuaternionT< T >::norm

Returns the norm of this quaternion.

Returns
Quaternion norm

◆ normalize() [1/2]

template<typename T >
bool Ocean::QuaternionT< T >::normalize

Normalizes the quaternion in place.

Returns
True, if the quaternion is not singular and could be normalized.
See also
normalized().

◆ normalize() [2/2]

template<typename T >
bool Ocean::QuaternionT< T >::normalize ( QuaternionT< T > &  normalizedQuaternion) const

Normalizes the quaternion and returns the result as parameter.

Parameters
normalizedQuaternionThe resulting normalized quaternion
Returns
True, if the quaternion is not singular and could be normalized.
See also
normalized().

◆ normalized()

template<typename T >
QuaternionT< T > Ocean::QuaternionT< T >::normalized

Returns the normalized quaternion.

Beware: This function does not throw an exception if the quaternion is singular and cannot be normalized.
Thus ensure that the quaternion is valid before calling this function.
In case, this quaternion is not valid, a default quaternion will be returned.

Returns
Normalized quaternion
See also
isValid(), normalize().

◆ operator!=()

template<typename T >
bool Ocean::QuaternionT< T >::operator!= ( const QuaternionT< T > &  right) const
inline

Returns whether two quaternions are not identical up to a small epsilon.

Parameters
rightThe right quaternion
Returns
True, if so

◆ operator()() [1/4]

template<typename T >
T * Ocean::QuaternionT< T >::operator()
inline

Access operator.

Returns
Pointer to the internal values

◆ operator()() [2/4]

template<typename T >
const T * Ocean::QuaternionT< T >::operator()
inline

Access operator.

Returns
Pointer to the internal values

◆ operator()() [3/4]

template<typename T >
T & Ocean::QuaternionT< T >::operator() ( const unsigned int  index)
inline

Element operator.

Beware: No range check will be done!

Parameters
indexThe index of the element to return [0, 3]
Returns
Specified element

◆ operator()() [4/4]

template<typename T >
T Ocean::QuaternionT< T >::operator() ( const unsigned int  index) const
inline

Element operator.

Beware: No range check will be done!

Parameters
indexThe index of the element to return [0, 3]
Returns
Specified element

◆ operator*() [1/3]

template<typename T >
QuaternionT< T > Ocean::QuaternionT< T >::operator* ( const QuaternionT< T > &  right) const

Combines two quaternion to a new combined rotation.

Parameters
rightThe right quaternion
Returns
Combined quaternion

◆ operator*() [2/3]

template<typename T >
QuaternionT< T > Ocean::QuaternionT< T >::operator* ( const RotationT< T > &  right) const
inline

Combines a angle-axis rotation with this quaternion.

Parameters
rightThe right angle-axis rotation
Returns
Combined quaternion rotation

◆ operator*() [3/3]

template<typename T >
VectorT3< T > Ocean::QuaternionT< T >::operator* ( const VectorT3< T > &  vector) const

Rotates a 3D vector by this quaternion.

Parameters
vector3D vector to rotate
Returns
Rotated 3D vector

◆ operator*=() [1/2]

template<typename T >
QuaternionT< T > & Ocean::QuaternionT< T >::operator*= ( const QuaternionT< T > &  right)
inline

Combines and assigns two quaternions.

Parameters
rightThe right quaternion
Returns
Reference to this quaternion

◆ operator*=() [2/2]

template<typename T >
QuaternionT< T > & Ocean::QuaternionT< T >::operator*= ( const RotationT< T > &  right)
inline

Combines and assigns a quaternion with a rotation.

Parameters
rightThe right quaternion
Returns
Reference to this quaternion

◆ operator==()

template<typename T >
bool Ocean::QuaternionT< T >::operator== ( const QuaternionT< T > &  right) const

Returns whether two quaternions are identical up to a small epsilon.

Parameters
rightThe right quaternion
Returns
True, if so

◆ operator[]() [1/2]

template<typename T >
T & Ocean::QuaternionT< T >::operator[] ( const unsigned int  index)
inline

Element operator.

Beware: No range check will be done!

Parameters
indexThe index of the element to return [0, 3]
Returns
Specified element

◆ operator[]() [2/2]

template<typename T >
T Ocean::QuaternionT< T >::operator[] ( const unsigned int  index) const
inline

Element operator.

Beware: No range check will be done!

Parameters
indexThe index of the element to return [0, 3]
Returns
Specified element

◆ slerp()

template<typename T >
QuaternionT< T > Ocean::QuaternionT< T >::slerp ( const QuaternionT< T > &  quaternion,
factor 
) const

Spherical linear interpolation between two quaternions.

This quaternion will be the resulting interpolation if 'factor == 0'.

Parameters
quaternionThe right quaternion which will be the resulting interpolation if 'factor == 1'
factorInterpolation factor has to be between [0, 1]
Returns
The interpolated quaternion

◆ smallestAngle()

template<typename T >
T Ocean::QuaternionT< T >::smallestAngle ( const QuaternionT< T > &  quaternion) const

Returns the smallest angle between two quaternion rotations.

In contrast to angle(), this function returns the smallest (absolute) angle with range [0, PI). Beware: Ensure that this quaternion is valid.

Parameters
quaternionSecond quaternion for angle determination, must be valid
Returns
Rotation angle in radian, with range [0, PI), 0 in case of an invalid quaternion
See also
angle().

◆ sqr()

template<typename T >
T Ocean::QuaternionT< T >::sqr

Returns the square of the quaternion norm.

Returns
Square of quaternion norm

◆ w() [1/2]

template<typename T >
T & Ocean::QuaternionT< T >::w
inline

Returns the w value of the quaternion.

Returns
w value

◆ w() [2/2]

template<typename T >
const T & Ocean::QuaternionT< T >::w
inline

Returns the w value of the quaternion.

Returns
w value

◆ x() [1/2]

template<typename T >
T & Ocean::QuaternionT< T >::x
inline

Returns the x value of the quaternion.

Returns
x value

◆ x() [2/2]

template<typename T >
const T & Ocean::QuaternionT< T >::x
inline

Returns the x value of the quaternion.

Returns
x value

◆ y() [1/2]

template<typename T >
T & Ocean::QuaternionT< T >::y
inline

Returns the y value of the quaternion.

Returns
x value

◆ y() [2/2]

template<typename T >
const T & Ocean::QuaternionT< T >::y
inline

Returns the y value of the quaternion.

Returns
x value

◆ z() [1/2]

template<typename T >
T & Ocean::QuaternionT< T >::z
inline

Returns the z value of the quaternion.

Returns
z value

◆ z() [2/2]

template<typename T >
const T & Ocean::QuaternionT< T >::z
inline

Returns the z value of the quaternion.

Returns
z value

Field Documentation

◆ values_

template<typename T >
T Ocean::QuaternionT< T >::values_[4] = {T(1), T(0), T(0), T(0)}
protected

The four values of the quaternion.


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