A quaternion class that represents 3D rotations and orientations. Four scalar values, [w,x,y,z], are used represent orientations and rotations. More...
#include <gz/math/Quaternion.hh>
Public Member Functions | |
constexpr | Quaternion () |
Default Constructor. | |
Quaternion (const Matrix3< T > &_mat) | |
Construct from rotation matrix. This constructor does not normalize the quaternion. | |
Quaternion (const T &_roll, const T &_pitch, const T &_yaw) | |
Construct a Quaternion from Euler angles, in radians. This constructor normalizes the quaternion. | |
constexpr | Quaternion (const T &_w, const T &_x, const T &_y, const T &_z) |
Constructor that initializes each value, [w, x, y, z], of the quaternion. This constructor does not normalize the quaternion. | |
Quaternion (const Vector3< T > &_axis, const T &_angle) | |
Constructor from an axis and angle. This constructor normalizes the quaternion. | |
Quaternion (const Vector3< T > &_rpy) | |
Construct a Quaternion from Euler angles, in radians. This constructor normalizes the quaternion. | |
void | AxisAngle (Vector3< T > &_axis, T &_angle) const |
Convert this quaternion to an axis and angle. | |
void | Correct () |
Correct any nan values in this quaternion. | |
T | Dot (const Quaternion< T > &_q) const |
Get the dot product of this quaternion with the give _q quaternion. | |
bool | Equal (const Quaternion &_q, const T &_tol) const |
Equality comparison test with a tolerance parameter. The tolerance is used with the equal function for each component of the quaternions. | |
Vector3< T > | Euler () const |
Return the rotation in Euler angles, in radians. | |
Quaternion< T > | Exp () const |
Return the exponent. | |
Quaternion< T > | Integrate (const Vector3< T > &_angularVelocity, const T _deltaT) const |
Integrate quaternion for constant angular velocity vector along specified interval _deltaT . Implementation based on: http://physicsforgames.blogspot.com/2010/02/quaternions.html. | |
Quaternion< T > | Inverse () const |
Get the inverse of this quaternion. | |
void | Invert () |
Invert the quaternion. The quaternion is first normalized, then inverted. | |
bool | IsFinite () const |
See if a quaternion is finite (e.g., not nan). | |
Quaternion< T > | Log () const |
Return the logarithm. | |
void | Normalize () |
Normalize the quaternion. | |
Quaternion< T > | Normalized () const |
Gets a normalized version of this quaternion. | |
bool | operator!= (const Quaternion< T > &_qt) const |
Not equal to operator. A tolerance of 0.001 is used with the equal function for each component of the quaternions. | |
Quaternion< T > | operator* (const Quaternion< T > &_q) const |
Multiplication operator. | |
Quaternion< T > | operator* (const T &_f) const |
Multiplication operator by a scalar. | |
Vector3< T > | operator* (const Vector3< T > &_v) const |
Vector3 multiplication operator. | |
Quaternion< T > | operator*= (const Quaternion< T > &_qt) |
Multiplication set operator. | |
Quaternion< T > | operator+ (const Quaternion< T > &_qt) const |
Addition operator. | |
Quaternion< T > | operator+= (const Quaternion< T > &_qt) |
Addition set operator. | |
Quaternion< T > | operator- () const |
Unary minus operator. | |
Quaternion< T > | operator- (const Quaternion< T > &_qt) const |
Subtraction operator. | |
Quaternion< T > | operator-= (const Quaternion< T > &_qt) |
Subtraction set operator. | |
bool | operator== (const Quaternion< T > &_qt) const |
Equality comparison operator. A tolerance of 0.001 is used with the equal function for each component of the quaternions. | |
T | Pitch () const |
Get the Euler pitch angle in radians. | |
T | Roll () const |
Get the Euler roll angle in radians. | |
Vector3< T > | RotateVector (const Vector3< T > &_vec) const |
Rotate a vector using the quaternion. | |
Vector3< T > | RotateVectorReverse (const Vector3< T > &_vec) const |
Get the reverse rotation of a vector by this quaternion. | |
void | Round (int _precision) |
Round all values to _precision decimal places. | |
void | Scale (T _scale) |
Scale this quaternion. | |
void | Set (T _w, T _x, T _y, T _z) |
Set this quaternion from 4 floating numbers. | |
void | SetFrom2Axes (const Vector3< T > &_v1, const Vector3< T > &_v2) |
Set this quaternion to represent rotation from vector _v1 to vector _v2, so that _v2.Normalize() == this * _v1.Normalize() holds. | |
void | SetFromAxisAngle (const Vector3< T > &_axis, T _a) |
Set the quaternion from an axis and angle. | |
void | SetFromAxisAngle (T _ax, T _ay, T _az, T _aa) |
Set the quaternion from an axis and angle. | |
void | SetFromEuler (const Vector3< T > &_vec) |
Set the quaternion from Euler angles. The order of operations is roll, pitch, yaw around a fixed body frame axis (the original frame of the object before rotation is applied). Roll is a rotation about x, pitch is about y, yaw is about z. | |
void | SetFromEuler (T _roll, T _pitch, T _yaw) |
Set the quaternion from Euler angles. | |
void | SetFromMatrix (const Matrix3< T > &_mat) |
Set from a rotation matrix. | |
void | SetW (T _v) |
Set the w component. | |
void | SetX (T _v) |
Set the x component. | |
void | SetY (T _v) |
Set the y component. | |
void | SetZ (T _v) |
Set the z component. | |
T & | W () |
Get a mutable w component. | |
T | W () const |
Get the w component. | |
T & | X () |
Get a mutable x component. | |
T | X () const |
Get the x component. | |
Vector3< T > | XAxis () const |
Return the X axis. | |
T & | Y () |
Get a mutable y component. | |
T | Y () const |
Get the y component. | |
T | Yaw () const |
Get the Euler yaw angle in radians. | |
Vector3< T > | YAxis () const |
Return the Y axis. | |
T & | Z () |
Get a mutable z component. | |
T | Z () const |
Get the z component. | |
Vector3< T > | ZAxis () const |
Return the Z axis. | |
Static Public Member Functions | |
static Quaternion< T > | EulerToQuaternion (const Vector3< T > &_vec) |
Convert Euler angles to a quaternion. | |
static Quaternion< T > | EulerToQuaternion (T _x, T _y, T _z) |
Convert Euler angles, in radians, to a quaternion. | |
static Quaternion< T > | Slerp (T _fT, const Quaternion< T > &_rkP, const Quaternion< T > &_rkQ, bool _shortestPath=false) |
Spherical linear interpolation between 2 quaternions, given the ends and an interpolation parameter between 0 and 1. | |
static Quaternion< T > | Squad (T _fT, const Quaternion< T > &_rkP, const Quaternion< T > &_rkA, const Quaternion< T > &_rkB, const Quaternion< T > &_rkQ, bool _shortestPath=false) |
Spherical quadratic interpolation given the ends and an interpolation parameter between 0 and 1. | |
Static Public Attributes | |
static const Quaternion & | Identity = detail::gQuaternionIdentity<T> |
A Quaternion initialized to identity. This is equivalent to math::Quaternion<T>(1, 0, 0, 0) | |
static const Quaternion & | Zero = detail::gQuaternionZero<T> |
A Quaternion initialized to zero. This is equivalent to math::Quaternion<T>(0, 0, 0, 0) | |
Detailed Description
class gz::math::Quaternion< T >
A quaternion class that represents 3D rotations and orientations. Four scalar values, [w,x,y,z], are used represent orientations and rotations.
The following two type definitions are provided:
Examples
- C++
- Ruby
Constructor & Destructor Documentation
◆ Quaternion() [1/6]
|
inlineconstexpr |
Default Constructor.
◆ Quaternion() [2/6]
|
inlineconstexpr |
Constructor that initializes each value, [w, x, y, z], of the quaternion. This constructor does not normalize the quaternion.
- Parameters
-
[in] _w W param [in] _x X param [in] _y Y param [in] _z Z param
◆ Quaternion() [3/6]
|
inline |
Construct a Quaternion from Euler angles, in radians. This constructor normalizes the quaternion.
- Parameters
-
[in] _roll Roll radians. [in] _pitch Pitch radians. [in] _yaw Yaw radians.
- See also
- SetFromEuler(T, T, T)
References Quaternion< T >::SetFromEuler().
◆ Quaternion() [4/6]
|
inline |
Constructor from an axis and angle. This constructor normalizes the quaternion.
- Parameters
-
[in] _axis The rotation axis. [in] _angle The rotation angle in radians.
References Quaternion< T >::SetFromAxisAngle().
◆ Quaternion() [5/6]
|
inlineexplicit |
Construct a Quaternion from Euler angles, in radians. This constructor normalizes the quaternion.
- Parameters
-
[in] _rpy Euler angles in radians.
References Quaternion< T >::SetFromEuler().
◆ Quaternion() [6/6]
|
inlineexplicit |
Construct from rotation matrix. This constructor does not normalize the quaternion.
- Parameters
-
[in] _mat Rotation matrix (must be orthogonal, the function doesn't check it)
References Quaternion< T >::SetFromMatrix().
Member Function Documentation
◆ AxisAngle()
Convert this quaternion to an axis and angle.
- Parameters
-
[out] _axis Rotation axis. [out] _angle CCW angle in radians.
References Matrix6< T >::Set().
Referenced by Quaternion< T >::Scale().
◆ Correct()
Correct any nan values in this quaternion.
References gz::math::equal(), and std::isfinite().
◆ Dot()
|
inline |
Get the dot product of this quaternion with the give _q quaternion.
- Parameters
-
[in] _q The other quaternion.
- Returns
- The dot product.
◆ Equal()
|
inline |
Equality comparison test with a tolerance parameter. The tolerance is used with the equal function for each component of the quaternions.
- Parameters
-
[in] _q The quaternion to compare against. [in] _tol equality tolerance.
- Returns
- True if the elements of the quaternions are equal within the tolerence specified by _tol.
References gz::math::equal().
Referenced by Quaternion< T >::operator==().
◆ Euler()
Return the rotation in Euler angles, in radians.
- Returns
- This quaternion as Euler angles.
References GZ_PI.
Referenced by Quaternion< T >::Pitch(), Quaternion< T >::Roll(), and Quaternion< T >::Yaw().
◆ EulerToQuaternion() [1/2]
|
inlinestatic |
Convert Euler angles to a quaternion.
- Parameters
-
[in] _vec The vector of angles, in radians, to convert.
- Returns
- The resulting quaternion
Referenced by Quaternion< T >::EulerToQuaternion().
◆ EulerToQuaternion() [2/2]
|
inlinestatic |
Convert Euler angles, in radians, to a quaternion.
- Parameters
-
[in] _x rotation along x in radians [in] _y rotation along y in radians [in] _z rotation along z in radians
- Returns
- The resulting quaternion.
References Quaternion< T >::EulerToQuaternion().
◆ Exp()
|
inline |
Return the exponent.
If q = A*(x*i+y*j+z*k) where (x, y, z) is unit length, then exp(q) = cos(A)+sin(A)*(x*i+y*j+z*k). If sin(A) is near zero, use exp(q) = cos(A)+A*(x*i+y*j+z*k) since A/sin(A) has limit 1.
- Returns
- The exponent.
◆ Integrate()
|
inline |
Integrate quaternion for constant angular velocity vector along specified interval _deltaT
. Implementation based on: http://physicsforgames.blogspot.com/2010/02/quaternions.html.
- Parameters
-
[in] _angularVelocity Angular velocity vector, specified in same reference frame as base of this quaternion. [in] _deltaT Time interval in seconds to integrate over.
- Returns
- Quaternion at integrated configuration.
References gz::math::MIN_D.
◆ Inverse()
|
inline |
Get the inverse of this quaternion.
- Returns
- Inverse quaternion
Referenced by Quaternion< T >::RotateVector(), and Quaternion< T >::RotateVectorReverse().
◆ Invert()
Invert the quaternion. The quaternion is first normalized, then inverted.
References Quaternion< T >::Normalize().
◆ IsFinite()
See if a quaternion is finite (e.g., not nan).
- Returns
- True if quaternion is finite.
References std::isfinite().
◆ Log()
|
inline |
Return the logarithm.
If q = cos(A)+sin(A)*(x*i+y*j+z*k) where (x, y, z) is unit length, then log(q) = A*(x*i+y*j+z*k). If sin(A) is near zero, use log(q) = sin(A)*(x*i+y*j+z*k) since sin(A)/A has limit 1.
- Returns
- The log.
◆ Normalize()
Normalize the quaternion.
Referenced by Quaternion< T >::Invert(), Quaternion< T >::SetFrom2Axes(), Quaternion< T >::SetFromAxisAngle(), and Quaternion< T >::SetFromEuler().
◆ Normalized()
|
inline |
Gets a normalized version of this quaternion.
- Returns
- a normalized quaternion
◆ operator!=()
|
inline |
Not equal to operator. A tolerance of 0.001 is used with the equal function for each component of the quaternions.
- Parameters
-
[in] _qt Quaternion for comparison.
- Returns
- True if any component of both quaternions is not within the tolerance of 0.001 of its counterpart.
◆ operator*() [1/3]
|
inline |
Multiplication operator.
- Parameters
-
[in] _q Quaternion for multiplication.
- Returns
- This quaternion multiplied by the parameter.
◆ operator*() [2/3]
|
inline |
Multiplication operator by a scalar.
- Parameters
-
[in] _f Factor.
- Returns
- Quaternion multiplied by the scalar.
◆ operator*() [3/3]
Vector3 multiplication operator.
- Parameters
-
[in] _v vector to multiply.
- Returns
- The result of the vector multiplication.
◆ operator*=()
|
inline |
Multiplication set operator.
- Parameters
-
[in] _qt Quaternion<T> for multiplication.
- Returns
- This quaternion multiplied by the parameter.
◆ operator+()
|
inline |
◆ operator+=()
|
inline |
◆ operator-() [1/2]
|
inline |
Unary minus operator.
- Returns
- Negation of each component of this quaternion.
◆ operator-() [2/2]
|
inline |
◆ operator-=()
|
inline |
Subtraction set operator.
- Parameters
-
[in] _qt Quaternion for subtraction.
- Returns
- This quaternion - qt.
◆ operator==()
|
inline |
Equality comparison operator. A tolerance of 0.001 is used with the equal function for each component of the quaternions.
- Parameters
-
[in] _qt Quaternion<T> for comparison.
- Returns
- True if each component of both quaternions is within the tolerance of 0.001 of its counterpart.
References Quaternion< T >::Equal().
◆ Pitch()
|
inline |
Get the Euler pitch angle in radians.
- Returns
- The pitch component.
References Quaternion< T >::Euler().
◆ Roll()
|
inline |
Get the Euler roll angle in radians.
- Returns
- The roll component.
References Quaternion< T >::Euler().
◆ RotateVector()
Rotate a vector using the quaternion.
- Parameters
-
[in] _vec Vector to rotate.
- Returns
- The rotated vector.
References Quaternion< T >::Inverse().
◆ RotateVectorReverse()
Get the reverse rotation of a vector by this quaternion.
- Parameters
-
[in] _vec The vector.
- Returns
- The reversed vector.
References Quaternion< T >::Inverse().
◆ Round()
Round all values to _precision decimal places.
- Parameters
-
[in] _precision the precision.
References gz::math::precision().
◆ Scale()
Scale this quaternion.
- Parameters
-
[in] _scale Amount to scale this quaternion
References Quaternion< T >::AxisAngle(), and Quaternion< T >::SetFromAxisAngle().
◆ Set()
Set this quaternion from 4 floating numbers.
- Parameters
-
[in] _w w [in] _x x [in] _y y [in] _z z
◆ SetFrom2Axes()
|
inline |
Set this quaternion to represent rotation from vector _v1 to vector _v2, so that _v2.Normalize() == this * _v1.Normalize() holds.
- Parameters
-
[in] _v1 The first vector. [in] _v2 The second vector.
Implementation inspired by http://stackoverflow.com/a/11741520/1076564
References Quaternion< T >::Normalize(), and Matrix6< T >::Set().
◆ SetFromAxisAngle() [1/2]
Set the quaternion from an axis and angle.
- Parameters
-
[in] _axis Axis [in] _a Angle in radians
References Quaternion< T >::SetFromAxisAngle().
◆ SetFromAxisAngle() [2/2]
Set the quaternion from an axis and angle.
- Parameters
-
[in] _ax X axis [in] _ay Y axis [in] _az Z axis [in] _aa Angle in radians
References Quaternion< T >::Normalize().
Referenced by Quaternion< T >::Quaternion(), Quaternion< T >::Scale(), and Quaternion< T >::SetFromAxisAngle().
◆ SetFromEuler() [1/2]
Set the quaternion from Euler angles. The order of operations is roll, pitch, yaw around a fixed body frame axis (the original frame of the object before rotation is applied). Roll is a rotation about x, pitch is about y, yaw is about z.
- Parameters
-
[in] _vec Euler angles in radians.
References Quaternion< T >::SetFromEuler().
Referenced by Quaternion< T >::Quaternion(), Quaternion< T >::Quaternion(), and Quaternion< T >::SetFromEuler().
◆ SetFromEuler() [2/2]
Set the quaternion from Euler angles.
- Parameters
-
[in] _roll Roll angle in radians. [in] _pitch Pitch angle in radians. [in] _yaw Yaw angle in radians.
References Quaternion< T >::Normalize().
◆ SetFromMatrix()
Set from a rotation matrix.
- Parameters
-
[in] _mat Rotation matrix (must be orthogonal, the function doesn't check it).
Implementation inspired by http://www.euclideanspace.com/maths/geometry/rotations/ conversions/matrixToQuaternion/
Referenced by Quaternion< T >::Quaternion().
◆ SetW()
Set the w component.
- Parameters
-
[in] _v The new value for the w quaternion component.
◆ SetX()
Set the x component.
- Parameters
-
[in] _v The new value for the x quaternion component.
◆ SetY()
Set the y component.
- Parameters
-
[in] _v The new value for the y quaternion component.
◆ SetZ()
Set the z component.
- Parameters
-
[in] _v The new value for the z quaternion component.
◆ Slerp()
|
inlinestatic |
Spherical linear interpolation between 2 quaternions, given the ends and an interpolation parameter between 0 and 1.
- Parameters
-
[in] _fT The interpolation parameter. [in] _rkP The beginning quaternion. [in] _rkQ The end quaternion. [in] _shortestPath When true, the rotation may be inverted to get to minimize rotation.
- Returns
- The result of the linear interpolation.
Referenced by OnePoleQuaternion::Process(), and Quaternion< T >::Squad().
◆ Squad()
|
inlinestatic |
Spherical quadratic interpolation given the ends and an interpolation parameter between 0 and 1.
- Parameters
-
[in] _fT the interpolation parameter. [in] _rkP The beginning quaternion. [in] _rkA First intermediate quaternion. [in] _rkB Second intermediate quaternion. [in] _rkQ The end quaternion. [in] _shortestPath When true, the rotation may be inverted to get to minimize rotation.
- Returns
- The result of the quadratic interpolation.
References Quaternion< T >::Slerp().
◆ W() [1/2]
|
inline |
Get a mutable w component.
- Returns
- The w quaternion component.
◆ W() [2/2]
|
inline |
Get the w component.
- Returns
- The w quaternion component.
◆ X() [1/2]
|
inline |
Get a mutable x component.
- Returns
- The x quaternion component.
◆ X() [2/2]
|
inline |
Get the x component.
- Returns
- The x quaternion component.
◆ XAxis()
Return the X axis.
- Returns
- the X axis of the vector.
◆ Y() [1/2]
|
inline |
Get a mutable y component.
- Returns
- The y quaternion component.
◆ Y() [2/2]
|
inline |
Get the y component.
- Returns
- The y quaternion component.
◆ Yaw()
|
inline |
◆ YAxis()
Return the Y axis.
- Returns
- the Y axis of the vector.
◆ Z() [1/2]
|
inline |
Get a mutable z component.
- Returns
- The z quaternion component.
◆ Z() [2/2]
|
inline |
Get the z component.
- Returns
- The z quaternion component.
◆ ZAxis()
Return the Z axis.
- Returns
- the Z axis of the vector.
Member Data Documentation
◆ Identity
|
static |
A Quaternion initialized to identity. This is equivalent to math::Quaternion<T>(1, 0, 0, 0)
◆ Zero
|
static |
A Quaternion initialized to zero. This is equivalent to math::Quaternion<T>(0, 0, 0, 0)
The documentation for this class was generated from the following files: