scsl 1.0.1
Shimmering Clarity Standard Library
Loading...
Searching...
No Matches
Public Member Functions | Friends | Related Symbols | List of all members
scmp::geom::Quaternion< T > Class Template Reference

Quaternions provide a representation of Orientation and rotations in three dimensions. More...

#include <Quaternion.h>

Public Member Functions

 Quaternion ()
 Construct an identity Quaternion.
 
 Quaternion (Vector< T, 3 > _axis, T _angle)
 Construct a Quaternion with an Axis and Angle of rotation.
 
 Quaternion (Vector< T, 4 > vector)
 
 Quaternion (std::initializer_list< T > ilst)
 An initializer list containing values for w, x, y, and z.
 
void SetEpsilon (T epsilon)
 Set the comparison tolerance for this Quaternion.
 
Vector< T, 3 > Axis () const
 Return the Axis of rotation of this Quaternion.
 
T Angle () const
 Return the Angle of rotation of this Quaternion.
 
T Dot (const Quaternion< T > &other) const
 Compute the Dot product of two quaternions.
 
T Norm () const
 Compute the Norm of a Quaternion.
 
Quaternion UnitQuaternion ()
 Return the unit Quaternion.
 
Quaternion Conjugate () const
 Compute the Conjugate of a Quaternion.
 
Quaternion Inverse () const
 Compute the Inverse of a Quaternion.
 
bool IsIdentity () const
 Determine whether this is an identity Quaternion.
 
bool IsUnitQuaternion () const
 Determine whether this is a unit Quaternion.
 
Vector< T, 4 > AsVector () const
 Convert to Vector form.
 
Vector< T, 3 > Rotate (Vector< T, 3 > vr) const
 Rotate Vector vr about this Quaternion.
 
Vector< T, 3 > Euler () const
 Return Euler angles for this Quaternion.
 
Quaternion operator+ (const Quaternion< T > &other) const
 Quaternion addition.
 
Quaternion operator- (const Quaternion< T > &other) const
 Quaternion subtraction.
 
Quaternion operator* (const T k) const
 Scalar multiplication.
 
Quaternion operator/ (const T k) const
 Scalar division.
 
Quaternion operator* (const Vector< T, 3 > &vector) const
 Quaternion Hamilton multiplication with a three- dimensional vector.
 
Quaternion operator* (const Quaternion< T > &other) const
 Quaternion Hamilton multiplication.
 
bool operator== (const Quaternion< T > &other) const
 Quaternion equivalence.
 
bool operator!= (const Quaternion< T > &other) const
 Quaternion non-equivalence.
 

Friends

std::ostream & operator<< (std::ostream &outs, const Quaternion< T > &q)
 Output a Quaternion to a stream in the form a + <i, j, k>.
 

Related Symbols

(Note that these are not member symbols.)

Quaternionf MakeQuaternion (Vector3F axis, float angle)
 Convenience Quaternion construction function.
 
Quaterniond MakeQuaternion (Vector3D axis, double angle)
 Convience Quaternion construction function.
 
template<typename T >
Quaternion< T > MakeQuaternion (Vector< T, 3 > axis, T angle)
 Convience Quaternion construction function.
 
Quaternionf FloatQuaternionFromEuler (Vector3F euler)
 COnstruct a Quaternion from Euler angles.
 
Quaterniond DoubleQuaternionFromEuler (Vector3D euler)
 COnstruct a Quaternion from Euler angles.
 

Detailed Description

template<typename T>
class scmp::geom::Quaternion< T >

Quaternions provide a representation of Orientation and rotations in three dimensions.

Quaternions encode rotations in three-dimensional space. While technically a MakeQuaternion is comprised of a real element and a complex vector<3>, for the purposes of this library, it is modeled as a floating point 4D vector of the form <w, x, y, z>, where x, y, and z represent an Axis of rotation in R3 and w the Angle, in radians, of the rotation about that Axis. Where Euler angles are concerned, the ZYX (or yaw, pitch, roll) sequence is used.

For information on the underlying vector type, see the documentation for scmp::geom::Vector.

Like vectors, quaternions carry an internal tolerance value ε that is used for floating point comparisons. The math namespace contains the default values used for this; generally, a tolerance of 0.0001 is considered appropriate for the uses of this library. The tolerance can be explicitly set with the SetEpsilon method.

Constructor & Destructor Documentation

◆ Quaternion() [1/4]

template<typename T >
scmp::geom::Quaternion< T >::Quaternion ( )
inline

Construct an identity Quaternion.

◆ Quaternion() [2/4]

template<typename T >
scmp::geom::Quaternion< T >::Quaternion ( Vector< T, 3 >  _axis,
T  _angle 
)
inline

Construct a Quaternion with an Axis and Angle of rotation.

A Quaternion may be initialised with a Vector<T, 3> Axis of rotation and an Angle of rotation. This doesn't do the Angle transforms to simplify internal operations.

Parameters
_axisA three-dimensional vector of the same type as the Quaternion.
_angleThe Angle of rotation about the Axis of rotation.

◆ Quaternion() [3/4]

template<typename T >
scmp::geom::Quaternion< T >::Quaternion ( Vector< T, 4 >  vector)
inline

A Quaternion may be initialised with a Vector<T, 4> comprised of the Axis of rotation followed by the Angle of rotation.

Parameters
vectorA vector in the form <w, x, y, z>.

◆ Quaternion() [4/4]

template<typename T >
scmp::geom::Quaternion< T >::Quaternion ( std::initializer_list< T ilst)
inline

An initializer list containing values for w, x, y, and z.

Parameters
ilstAn initial set of values in the form <w, x, y, z>.

Member Function Documentation

◆ Angle()

template<typename T >
T scmp::geom::Quaternion< T >::Angle ( ) const
inline

Return the Angle of rotation of this Quaternion.

Returns
the Angle of rotation of this Quaternion.

◆ AsVector()

template<typename T >
Vector< T, 4 > scmp::geom::Quaternion< T >::AsVector ( ) const
inline

Convert to Vector form.

Return the Quaternion as a Vector<T, 4>, with the Axis of rotation followed by the Angle of rotation.

Returns
A vector representation of the Quaternion.

◆ Axis()

template<typename T >
Vector< T, 3 > scmp::geom::Quaternion< T >::Axis ( ) const
inline

Return the Axis of rotation of this Quaternion.

Returns
The Axis of rotation of this Quaternion.

◆ Conjugate()

template<typename T >
Quaternion scmp::geom::Quaternion< T >::Conjugate ( ) const
inline

Compute the Conjugate of a Quaternion.

Returns
The Conjugate of this Quaternion.

◆ Dot()

template<typename T >
T scmp::geom::Quaternion< T >::Dot ( const Quaternion< T > &  other) const
inline

Compute the Dot product of two quaternions.

Parameters
otherAnother Quaternion.
Returns
The Dot product between the two quaternions.

◆ Euler()

template<typename T >
Vector< T, 3 > scmp::geom::Quaternion< T >::Euler ( ) const
inline

Return Euler angles for this Quaternion.

Return the Euler angles for this Quaternion as a vector of <yaw, pitch, roll>.

Warning
Users of this function should watch out for gimbal lock.
Returns
A vector<T, 3> containing <yaw, pitch, roll>

◆ Inverse()

template<typename T >
Quaternion scmp::geom::Quaternion< T >::Inverse ( ) const
inline

Compute the Inverse of a Quaternion.

Returns
The Inverse of this Quaternion.

◆ IsIdentity()

template<typename T >
bool scmp::geom::Quaternion< T >::IsIdentity ( ) const
inline

Determine whether this is an identity Quaternion.

Returns
true if this is an identity Quaternion.

◆ IsUnitQuaternion()

template<typename T >
bool scmp::geom::Quaternion< T >::IsUnitQuaternion ( ) const
inline

Determine whether this is a unit Quaternion.

Returns
true if this is a unit Quaternion.

◆ Norm()

template<typename T >
T scmp::geom::Quaternion< T >::Norm ( ) const
inline

Compute the Norm of a Quaternion.

Treating the Quaternion as a Vector<T, 4>, this is the same process as computing the Magnitude.

Returns
A non-negative real number.

◆ operator!=()

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

Quaternion non-equivalence.

Parameters
otherThe Quaternion to check inequality against.
Returns
True if the two quaternions are unequal within their tolerance.

◆ operator*() [1/3]

template<typename T >
Quaternion scmp::geom::Quaternion< T >::operator* ( const Quaternion< T > &  other) const
inline

Quaternion Hamilton multiplication.

Parameters
otherThe other Quaternion to multiply with this one.
Returns
The Hamilton product of the two quaternions.

◆ operator*() [2/3]

template<typename T >
Quaternion scmp::geom::Quaternion< T >::operator* ( const T  k) const
inline

Scalar multiplication.

Parameters
kThe scaling value.
Returns
A scaled Quaternion.

◆ operator*() [3/3]

template<typename T >
Quaternion scmp::geom::Quaternion< T >::operator* ( const Vector< T, 3 > &  vector) const
inline

Quaternion Hamilton multiplication with a three- dimensional vector.

This is done by treating the vector as a pure Quaternion (e.g. with an Angle of rotation of 0).

Parameters
vectorThe vector to multiply with this Quaternion.
Returns
The Hamilton product of the Quaternion and vector.

◆ operator+()

template<typename T >
Quaternion scmp::geom::Quaternion< T >::operator+ ( const Quaternion< T > &  other) const
inline

Quaternion addition.

Parameters
otherThe Quaternion to be added with this one.
Returns
The result of adding the two quaternions together.

◆ operator-()

template<typename T >
Quaternion scmp::geom::Quaternion< T >::operator- ( const Quaternion< T > &  other) const
inline

Quaternion subtraction.

Parameters
otherThe Quaternion to be subtracted from this one.
Returns
The result of subtracting the other Quaternion from this one.

◆ operator/()

template<typename T >
Quaternion scmp::geom::Quaternion< T >::operator/ ( const T  k) const
inline

Scalar division.

Parameters
kThe scalar divisor.
Returns
A scaled Quaternion.

◆ operator==()

template<typename T >
bool scmp::geom::Quaternion< T >::operator== ( const Quaternion< T > &  other) const
inline

Quaternion equivalence.

Parameters
otherThe Quaternion to check equality against.
Returns
True if the two quaternions are equal within their tolerance.

◆ Rotate()

template<typename T >
Vector< T, 3 > scmp::geom::Quaternion< T >::Rotate ( Vector< T, 3 >  vr) const
inline

Rotate Vector vr about this Quaternion.

Parameters
vrThe vector to be rotated.
Returns
The rotated vector.

◆ SetEpsilon()

template<typename T >
void scmp::geom::Quaternion< T >::SetEpsilon ( T  epsilon)
inline

Set the comparison tolerance for this Quaternion.

Parameters
epsilonA tolerance value.

◆ UnitQuaternion()

template<typename T >
Quaternion scmp::geom::Quaternion< T >::UnitQuaternion ( )
inline

Return the unit Quaternion.

Returns
The unit Quaternion.

Friends And Related Symbol Documentation

◆ DoubleQuaternionFromEuler()

template<typename T >
Quaterniond DoubleQuaternionFromEuler ( Vector3D  euler)
related

COnstruct a Quaternion from Euler angles.

Given a vector of Euler angles in ZYX sequence (e.g. yaw, pitch, roll), return a Quaternion.

Parameters
eulerA vector Euler Angle in ZYX sequence.
Returns
A Quaternion representation of the Orientation represented by the Euler angles.

◆ FloatQuaternionFromEuler()

template<typename T >
Quaternionf FloatQuaternionFromEuler ( Vector3F  euler)
related

COnstruct a Quaternion from Euler angles.

Given a vector of Euler angles in ZYX sequence (e.g. yaw, pitch, roll), return a Quaternion.

Parameters
eulerA vector Euler Angle in ZYX sequence.
Returns
A Quaternion representation of the Orientation represented by the Euler angles.

◆ MakeQuaternion() [1/3]

template<typename T >
Quaterniond MakeQuaternion ( Vector3D  axis,
double  angle 
)
related

Convience Quaternion construction function.

Return a double Quaternion scaled appropriately from a vector and Angle, e.g. Angle = cos(Angle / 2), Axis.UnitVector() * sin(Angle / 2).

Parameters
axisThe Axis of rotation.
angleThe Angle of rotation.
Returns
A Quaternion.

◆ MakeQuaternion() [2/3]

template<typename T >
Quaternionf MakeQuaternion ( Vector3F  axis,
float  angle 
)
related

Convenience Quaternion construction function.

Return a float Quaternion scaled appropriately from a vector and Angle, e.g. angle = cos(Angle / 2), Axis.UnitVector() * sin(Angle / 2).

Parameters
axisThe Axis of rotation.
angleThe Angle of rotation.
Returns
A Quaternion.

◆ MakeQuaternion() [3/3]

template<typename T >
Quaternion< T > MakeQuaternion ( Vector< T, 3 >  axis,
angle 
)
related

Convience Quaternion construction function.

Return a double Quaternion scaled appropriately from a vector and Angle, e.g. Angle = cos(Angle / 2), Axis.UnitVector() * sin(Angle / 2).

Parameters
axisThe Axis of rotation.
angleThe Angle of rotation.
Returns
A Quaternion.

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream &  outs,
const Quaternion< T > &  q 
)
friend

Output a Quaternion to a stream in the form a + <i, j, k>.

Todo:
improve the formatting.
Parameters
outsAn output stream
qA Quaternion
Returns
The output stream

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