Ocean
|
This class implements a unit quaternion rotation. More...
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... | |
T | norm () const |
Returns the norm of this quaternion. More... | |
T | sqr () const |
Returns the square of the quaternion norm. More... | |
T | dot (const QuaternionT< T > &quaternion) const |
Returns the dot product between this quaternion and a second quaternion. More... | |
T | angle () const |
Returns the rotation angle defined by the quaternion. More... | |
T | angle (const QuaternionT< T > &quaternion) const |
Returns the angle between two quaternion rotations. More... | |
T | smallestAngle (const QuaternionT< T > &quaternion) const |
Returns the smallest angle between two quaternion rotations. More... | |
T | 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... | |
T | operator[] (const unsigned int index) const |
Element operator. More... | |
T & | operator[] (const unsigned int index) |
Element operator. More... | |
T | 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 | |
T | values_ [4] = {T(1), T(0), T(0), T(0)} |
The four values of the quaternion. More... | |
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
T | Data type used to represent the quaternion values |
typedef T Ocean::QuaternionT< T >::Type |
Definition of the used data type.
|
default |
Creates a new quaternion with default values, representation an identity rotation.
|
explicit |
Creates a new quaternion with either default values (representation an identity rotation) or an invalid rotation.
toIdentity | True, to create an identity rotation; False, to created an invalid rotation |
|
inlineexplicit |
Copies a quaternion with different element data type than T.
quaternion | The quaternion object to be copied |
U | The element data type of the given quaternion |
Ocean::QuaternionT< T >::QuaternionT | ( | const T | w, |
const T | x, | ||
const T | y, | ||
const T | z | ||
) |
Creates a new quaternion by four given values.
w | W value of the quaternion, with range (-infinity, infinity) |
x | X value of the quaternion, with range (-infinity, infinity) |
y | Y value of the quaternion, with range (-infinity, infinity) |
z | Z value of the quaternion, with range (-infinity, infinity) |
Ocean::QuaternionT< T >::QuaternionT | ( | const VectorT3< T > & | axis, |
const T | angle | ||
) |
Creates a new quaternion by a given axis and rotation angle.
axis | The axis of the angle-axis rotation with unit length |
angle | The angle of the angle-axis rotation in radian, with range (-infinity, infinity), however will be converted to the range [0.0, 2 * PI) |
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.
reference | The reference vector, with length 1 |
offset | The offset vector, with length 1 |
|
explicit |
Creates a new quaternion by a given angle-axis rotation.
rotation | The rotation to create the quaternion from, must be valid |
|
explicit |
Creates a new quaternion by a given Euler rotation.
euler | Rotation to create the quaternion from, must be valid |
|
explicit |
Creates a new quaternion by a given 3x3 rotation matrix.
matrix | Rotation matrix to create the quaternion from, with determinant 1 |
|
explicit |
Creates a new quaternion by a given 4x4 homogeneous transformation matrix.
transformation | The transformation matrix to create the quaternion from |
|
explicit |
Creates a new quaternion by a 4D vector.
vector | The vector holding the four quaternion parameter |
|
explicit |
Creates a new quaternion by an array with at least four elements.
arrayValue | Array with elements, must be valid |
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.
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.
quaternion | Second quaternion for angle determination, must be valid |
QuaternionT< T > Ocean::QuaternionT< T >::conjugate |
Returns the conjugate of this quaternion.
The conjugated quaternion is defined as: (w - xi - yj - zk)
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.
quaternion | Second quaternion for value determination, must be valid |
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).
quaternion | The second quaternion for dot product calculation |
bool Ocean::QuaternionT< T >::invert |
Inverts this quaternion in place.
bool Ocean::QuaternionT< T >::invert | ( | QuaternionT< T > & | invertedQuaternion | ) | const |
Inverts this quaternion and returns the result as parameter.
invertedQuaternion | The resulting inverted quaternion |
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.
|
inline |
Returns whether two quaternions are equal up to a specified epsilon.
quaternion | Second quaternion to compare |
eps | The epsilon to be used, with range [0, infinity) |
bool Ocean::QuaternionT< T >::isValid |
Returns whether this quaternion is a valid unit quaternion.
T Ocean::QuaternionT< T >::norm |
Returns the norm of this quaternion.
bool Ocean::QuaternionT< T >::normalize |
Normalizes the quaternion in place.
bool Ocean::QuaternionT< T >::normalize | ( | QuaternionT< T > & | normalizedQuaternion | ) | const |
Normalizes the quaternion and returns the result as parameter.
normalizedQuaternion | The resulting normalized quaternion |
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.
|
inline |
Returns whether two quaternions are not identical up to a small epsilon.
right | The right quaternion |
|
inline |
Access operator.
|
inline |
Access operator.
|
inline |
Element operator.
Beware: No range check will be done!
index | The index of the element to return [0, 3] |
|
inline |
Element operator.
Beware: No range check will be done!
index | The index of the element to return [0, 3] |
QuaternionT< T > Ocean::QuaternionT< T >::operator* | ( | const QuaternionT< T > & | right | ) | const |
Combines two quaternion to a new combined rotation.
right | The right quaternion |
|
inline |
Combines a angle-axis rotation with this quaternion.
right | The right angle-axis rotation |
VectorT3< T > Ocean::QuaternionT< T >::operator* | ( | const VectorT3< T > & | vector | ) | const |
Rotates a 3D vector by this quaternion.
vector | 3D vector to rotate |
|
inline |
Combines and assigns two quaternions.
right | The right quaternion |
|
inline |
Combines and assigns a quaternion with a rotation.
right | The right quaternion |
bool Ocean::QuaternionT< T >::operator== | ( | const QuaternionT< T > & | right | ) | const |
Returns whether two quaternions are identical up to a small epsilon.
right | The right quaternion |
|
inline |
Element operator.
Beware: No range check will be done!
index | The index of the element to return [0, 3] |
|
inline |
Element operator.
Beware: No range check will be done!
index | The index of the element to return [0, 3] |
QuaternionT< T > Ocean::QuaternionT< T >::slerp | ( | const QuaternionT< T > & | quaternion, |
T | factor | ||
) | const |
Spherical linear interpolation between two quaternions.
This quaternion will be the resulting interpolation if 'factor == 0'.
quaternion | The right quaternion which will be the resulting interpolation if 'factor == 1' |
factor | Interpolation factor has to be between [0, 1] |
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.
quaternion | Second quaternion for angle determination, must be valid |
T Ocean::QuaternionT< T >::sqr |
Returns the square of the quaternion norm.
|
inline |
Returns the w value of the quaternion.
|
inline |
Returns the w value of the quaternion.
|
inline |
Returns the x value of the quaternion.
|
inline |
Returns the x value of the quaternion.
|
inline |
Returns the y value of the quaternion.
|
inline |
Returns the y value of the quaternion.
|
inline |
Returns the z value of the quaternion.
|
inline |
Returns the z value of the quaternion.
|
protected |
The four values of the quaternion.