Singularity-free spatial rotations class. More...
#include <rotation.h>
Public Member Functions | |
Rotation () | |
Default constructor. Creates the [0.0, 0.0, 0.0, 1.0] quaternion. | |
Rotation (const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w) | |
Rotation (const Scalar *r) | |
Rotation (const Unit3 &axis, const Scalar &angle) | |
Constructor for axis-angle input. | |
Rotation (const Scalar &yaw, const Scalar &pitch, const Scalar &roll) | |
Rotation (const Matrix3x3 &mat) | |
Constructor for rotation matrix. | |
Rotation (const Unit3 &u, const Unit3 &v, const Unit3 &r, const Unit3 &s) | |
Constructor for two pairs of independent unit vectors. | |
Rotation (const Unit3 &u, const Unit3 &v) | |
Rotation (const Quaternion &q) | |
Constructor for Quaternion input. | |
Rotation & | operator= (const Quaternion &q) |
Vector3 | operator() (const Vector3 &v) const |
Applies rotation to input vector. | |
bool | operator== (const Rotation &r) const |
bool | operator!= (const Rotation &r) const |
Scalar | angleCos (const Rotation &r) const |
Cosine of the angle between unit quatenions. | |
Scalar | angle (const Rotation &r) const |
Rotation | inverse () const |
Quaternion inverse. | |
void | getAxisAngle (Unit3 &axis, Scalar &angle) const |
void | getYpr (Scalar &yaw, Scalar &pitch, Scalar &roll) const |
Matrix3x3 | getMatrix () const |
void | setValue (const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w) |
Sets unit quaternion values. | |
void | setValue (const Scalar *r) |
Sets unit quaternion values from pointer input. | |
void | setAxisAngle (const Unit3 &axis, const Scalar &angle) |
void | setYpr (const Scalar &yaw, const Scalar &pitch, const Scalar &roll) |
void | setMatrix (const Matrix3x3 &mat) |
void | setTwoPairs (const Unit3 &u, const Unit3 &v, const Unit3 &r, const Unit3 &s) |
void | setOnePair (const Unit3 &u, const Unit3 &v) |
![]() | |
Quaternion () | |
Default constructor. Creates the [0.0, 0.0, 0.0, 1.0] quaternion. | |
Quaternion (const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w) | |
Constructor for four input values, where ![]() | |
Quaternion (const Scalar *q) | |
Constructor for pointer input. | |
Scalar & | operator[] (size_t n) |
Unchecked element access. | |
const Scalar & | operator[] (size_t n) const |
Unchecked element access. | |
Quaternion & | operator+= (const Quaternion &q) |
Quaternion & | operator-= (const Quaternion &q) |
Quaternion & | operator*= (const Quaternion &q) |
Quaternion product (not memberwise product). | |
Quaternion & | operator*= (const Scalar &s) |
Scalar-quaternion product. | |
Quaternion & | operator/= (const Scalar &s) |
Scalar-quaternion division. | |
bool | operator== (const Quaternion &q) const |
bool | operator!= (const Quaternion &q) const |
Scalar | dot (const Quaternion &q) const |
Dot product. | |
Scalar | length2 () const |
Squared quaternion length. | |
Scalar | length () const |
Quaternion length. | |
Quaternion & | normalize () |
Normalize quaternion to unit length. | |
Scalar | distance2 (const Quaternion &q) const |
Squared distance between quaternions. | |
Scalar | distance (const Quaternion &q) const |
Distance between quaternions. | |
Scalar | angleCos (const Quaternion &q) const |
Cosine of the angle between quaternions. | |
Scalar | angle (const Quaternion &q) const |
Angle between quaternions in the range [0, pi] expressed in radians. | |
Quaternion | conjugate () const |
Quaternion conjugate. | |
Quaternion | slerp (const Quaternion &q, const Scalar &t) const |
Spherical linear interpolation/extrapolation with input quaternion. | |
Scalar & | at (size_t n) |
Checked element access. | |
const Scalar & | at (size_t n) const |
Checked element access. |
Additional Inherited Members | |
![]() | |
Scalar | m_co [4] |
Singularity-free spatial rotations class.
The Rotation class permits defining 3D rotations from quaternion, rotation matrix, axis-angle, and yaw, pitch, and roll representations. Also, any of the above representations can be extracted from an existing Rotation instance.
Rotations can be applied to a vector using the () operator, and can be combined by means of the product operator.
The Rotation class is implemented using unit quaternions, so it provides the usual operators and functions used for expressing and manipulating quaternions, including spherical linear interpolation/extrapolation (SLERP).
The main difference from Quaternion, its base class, is that the quaternion length is always guaranteed to be unity.
Let be a unit quaternion, then the following notations are analogous:
with .
This is an example of how to use the Rotation class:
|
inline |
Constructor for four input values.
The input values need not define a quaternion of unit length.
|
inlineexplicit |
Constructor for pointer input.
The input values need not define a quaternion of unit length.
|
inline |
Constructor for yaw, pitch, and roll angle input. Rotations angles are measured about the fixed reference frame.
yaw | Rotation around the z axis |
pitch | Rotation around the y axis |
roll | Rotation around the x axis |
Constructor for two unit vectors (obtains rotation that transforms u into v ).
|
inline |
Angle between unit quatenions in the range expressed in radians.
|
inline |
Gets axis-angle representation of rotation, where:
and
where .
Of the two possible rotation angles, the one belonging to is chosen.
|
inline |
Gets matrix representation of rotation according to:
|
inline |
Gets \a yaw, \a pitch, and \a roll angles representation of rotation
according to:
Angular values belong to the interval . Since the above equation for the pitch angle has two solutions in the mentioned interval, the solution closest to the initial value of pitch is chosen.
Singularities (i.e., gimbal lock) arise when the pitch angle equals or
. In such cases the initial value of the roll angle is used, and the yaw angle is calculated as follows:
If ,
If ,
where
Rotations angles are measured about the fixed reference frame.
yaw | Rotation around the z axis |
pitch | Rotation around the y axis |
roll | Rotation around the x axis |
|
inline |
Assignment operator.
q | The Rotation to assign to this object. |
|
inline |
Equality operator. The comparison criterion is that the angle between the two quaternions must be equal to zero.
|
inline |
Sets quaternion from axis-angle input according to:
where represents the rotation axis and
represents the rotation angle.
|
inline |
Sets quaternion from rotation matrix.
Given a rotation matrix
the associated quaternion is given by one of the following relations:
Sets quaternion from one pair of unit vectors. The resulting rotation transforms vector u into vector v. This is equivalent to setting the rotation through an axis-angle pair, where the axis is a vector perpendicular to both u and v, and the angle is the angle between u and v.
|
inline |
Sets quaternion from two pairs of unit vectors.
Given two pairs of independent unit vectors and
, the rotation
places
parallel to
and
in the plane defined by
and
. If
, then
will additionally be parallel to
.
where and
are the orthonormal basis associated to
and
, respectively.
|
inline |
Sets quaternion from \a yaw, \a pitch, and \a roll input according to:
The rotation matrix associated to the yaw, pitch and roll convention is:
with and
.
The yaw, pitch, and roll angles represent rotations about the fixed z, y, and x axes, respectively.
Other names given to this rotation convention are X-Y-Z fixed angles and 3-2-1 Euler Angle Sequence