#include <MQuaternion.h>
Quaternion math.
This class provides methods for working with Quaternions. Quaternions can be used to specify orientations and rotations of 3-D objects relative to a starting reference, similar to the way that cartesian vectors can be used to specify positions and translations of 3-D objects relative to an origin. Quaternions represent orientations as a single rotation, just as rectangular co-ordinates represent position as a single vector.
Public Member Functions | |
MQuaternion () | |
The default class constructor. More... | |
MQuaternion (const MQuaternion &src) | |
The copy constructor. More... | |
MQuaternion (double xx, double yy, double zz, double ww) | |
Class constructor. More... | |
MQuaternion (const double q[4]) | |
Class constructor. More... | |
MQuaternion (const MVector &a, const MVector &b) | |
Class constructor. More... | |
MQuaternion (const MVector &a, const MVector &b, double angleFactor) | |
Class constructor. More... | |
MQuaternion (double angle, const MVector &axisb) | |
This constructor creates a new quaternion whose rotation is expressed by a pivot axis and a rotation (in radians) about that axis. More... | |
~MQuaternion () | |
Class destructor. | |
MQuaternion & | operator= (const MQuaternion &src) |
The assignment operator. More... | |
MQuaternion & | operator= (const MMatrix &matrix) |
Convert the given 4X4 homogeneous rotation matrix to a quaternion of unit length. More... | |
MQuaternion & | operator= (const MEulerRotation &matrix) |
Convert the given euler rotation to a quaternion. More... | |
MMatrix | asMatrix () const |
Converts a quaternion to a 4X4 homogeneous rotation matrix. More... | |
MEulerRotation | asEulerRotation () const |
Converts a quaternion to an euler rotation. More... | |
MQuaternion & | setAxisAngle (const MVector &axis, double theta) |
Sets this quaternion to be the rotation as expressed by a pivot axis and a rotation theta (in radians) about that axis. More... | |
bool | getAxisAngle (MVector &axis, double &theta) const |
Converts this quaternion into a user understandable representation. More... | |
MQuaternion & | setToXAxis (double theta) |
Sets this quaternion to be the rotation about the X axis of theta (in radians). More... | |
MQuaternion & | setToYAxis (double theta) |
Sets this quaternion to be the rotation about the Y axis of theta (in radians). More... | |
MQuaternion & | setToZAxis (double theta) |
Sets this quaternion to be the rotation about the Z axis of theta (in radians). More... | |
MStatus | get (double dest[4]) const |
Extracts the x, y, z, and w components of the quaternion and places them in elements 0, 1, 2, and 3 of the double array passed. More... | |
double | operator[] (unsigned int i) const |
The index operator. More... | |
MQuaternion | operator+ (const MQuaternion &other) const |
The quaternion addition operator. More... | |
MQuaternion | operator* (const MQuaternion &other) const |
This quaternion multiplication operator. More... | |
MQuaternion & | operator*= (const MQuaternion &rhs) |
The in place quaternion multiplication operator. More... | |
MQuaternion | operator- (const MQuaternion &other) const |
The quaternion subtraction operator. More... | |
MQuaternion | operator- () const |
The unary minus operator. More... | |
MQuaternion & | negateIt () |
Performs an in place negation of the quaternion. More... | |
bool | operator== (const MQuaternion &other) const |
The quaternion equality operator. More... | |
bool | operator!= (const MQuaternion &other) const |
The quaternion inequality operator. More... | |
bool | isEquivalent (const MQuaternion &other, double tolerance=kQuaternionEpsilon) const |
This method returns true if this quaternion is equal, within some given tolerance, to the other quaternion. More... | |
MQuaternion & | scaleIt (double scale) |
Performs an in place scaling of the quaternion. More... | |
MQuaternion | normal () const |
Returns the normal of this quaternion. More... | |
MQuaternion & | normalizeIt () |
Performs an in place normalization of this quaternion. More... | |
MQuaternion | conjugate () const |
Returns the conjugate of this quaternion. More... | |
MQuaternion & | conjugateIt () |
Performs an in place conjugation of this quaternion. More... | |
MQuaternion | inverse () const |
Returns the inverse of this quaternion. More... | |
MQuaternion & | invertIt () |
Performs an in place inversion of this quaternion. More... | |
MQuaternion | log () const |
Returns the natural log of a quaternion. More... | |
MQuaternion | exp () const |
Exponentiates a quaternion that has a scalar part of zero. More... | |
double & | operator[] (unsigned int i) |
NO SCRIPT SUPPORT. More... | |
operator MMatrix () const | |
NO SCRIPT SUPPORT. More... | |
Public Attributes | |
double | x |
The quaternion's imaginary x component. | |
double | y |
The quaternion's imaginary y component. | |
double | z |
The quaternion's imaginary z component. | |
double | w |
The quaternion's real component. | |
Static Public Attributes | |
static const MQuaternion | identity |
The multiplicative identity. | |
Friends | |
OPENMAYA_EXPORT MQuaternion | operator* (double scale, const MQuaternion &other) |
NO SCRIPT SUPPORT. More... | |
OPENMAYA_EXPORT MQuaternion | slerp (const MQuaternion &p, const MQuaternion &q, double t) |
Spherical linear interpolation (abbreviated as slerp) of unit quaternions. More... | |
OPENMAYA_EXPORT MQuaternion | slerp (const MQuaternion &p, const MQuaternion &q, double t, short spin) |
NO SCRIPT SUPPORT. More... | |
OPENMAYA_EXPORT MQuaternion | dslerp (const MQuaternion &p, const MQuaternion &q, double t, int dir) |
NO SCRIPT SUPPORT. More... | |
OPENMAYA_EXPORT MQuaternion | squad (const MQuaternion &p, const MQuaternion &a, const MQuaternion &b, const MQuaternion &q, double t) |
NO SCRIPT SUPPORT. More... | |
OPENMAYA_EXPORT MQuaternion | squad (const MQuaternion &p, const MQuaternion &a, const MQuaternion &b, const MQuaternion &q, double t, short spin) |
NO SCRIPT SUPPORT. More... | |
OPENMAYA_EXPORT MQuaternion | squadPt (const MQuaternion &q0, const MQuaternion &q1, const MQuaternion &q2) |
NO SCRIPT SUPPORT. More... | |
OPENMAYA_EXPORT std::ostream & | operator<< (std::ostream &os, const MQuaternion &q) |
NO SCRIPT SUPPORT. More... | |
MQuaternion | ( | ) |
The default class constructor.
Initializes the quaternion to the multiplicative identity.
MQuaternion | ( | const MQuaternion & | src | ) |
The copy constructor.
Creates a new quaternion and initializes it to the same values as the given quaternion.
[in] | src | the quaternion object to copy |
MQuaternion | ( | double | xx, |
double | yy, | ||
double | zz, | ||
double | ww | ||
) |
Class constructor.
Initializes the quaternion with the explicit x, y, z, and w values provided as arguments.
[in] | xx | the x component of the quaternion |
[in] | yy | the y component of the quaternion |
[in] | zz | the z component of the quaternion. |
[in] | ww | the w component of the quaternion. |
MQuaternion | ( | const double | q[4] | ) |
Class constructor.
Initializes the quaternion with the explicit x, y, z, and w values provided in the given double array.
[in] | q | the 4 element array containing the initial x, y, z, and w values |
MQuaternion | ( | const MVector & | a, |
const MVector & | b | ||
) |
Class constructor.
Creates a new quaternion that will rotate vector a into vector b about their mutually perpendicular axis.
[in] | a | vector to rotate from |
[in] | b | vector to rotate to |
MQuaternion | ( | const MVector & | a, |
const MVector & | b, | ||
double | angleFactor | ||
) |
Class constructor.
Creates a new quaternion that will rotate vector a into vector b about their mutually perpendicular axis by a given factor.
[in] | a | vector to rotate from |
[in] | b | vector to rotate to |
[in] | angleFactor | the factor by which the rotation should be multiplied; a factor of 1.0 is equivalent to a rotation of vector a into vector b |
MQuaternion | ( | double | angle, |
const MVector & | axis | ||
) |
This constructor creates a new quaternion whose rotation is expressed by a pivot axis and a rotation (in radians) about that axis.
If the length of the axis is too small the quaternion returned will be the identity quaternion.
[in] | angle | the amount of rotation around the axis |
[in] | axis | the axis about which the rotation occurs |
MQuaternion & operator= | ( | const MQuaternion & | src | ) |
The assignment operator.
[in] | src | the source quaternion |
MQuaternion & operator= | ( | const MMatrix & | matrix | ) |
Convert the given 4X4 homogeneous rotation matrix to a quaternion of unit length.
This methods always returns a quaternion of unit length if it is given a proper orthogonal matrix. A proper othogonal matrix is one such that the determinant of the matrix is one. (If the determinant were -1, this would imply that the orthogonal matrix is also producing a reflection, in addition to a rotation.)
[in] | matrix | the matrix to be converted to a quaternion |
MQuaternion & operator= | ( | const MEulerRotation & | euler | ) |
Convert the given euler rotation to a quaternion.
[in] | euler | the euler rotation to be converted to a quaternion |
MMatrix asMatrix | ( | ) | const |
Converts a quaternion to a 4X4 homogeneous rotation matrix.
The construction of the matrix assumes that the vectors are going to be multiplied on the left side of the matrix. If the quaternion's length has degenerated, this method will still produce a well behaved matrix.
ReturnValue
MEulerRotation asEulerRotation | ( | ) | const |
Converts a quaternion to an euler rotation.
ReturnValue
MQuaternion & setAxisAngle | ( | const MVector & | axis, |
double | theta | ||
) |
Sets this quaternion to be the rotation as expressed by a pivot axis and a rotation theta (in radians) about that axis.
If the axis is too small the quaternion returned will be the identity quaternion.
[in] | axis | the axis about which to rotate |
[in] | theta | the angle of rotation about the axis in radians |
bool getAxisAngle | ( | MVector & | axis, |
double & | theta | ||
) | const |
Converts this quaternion into a user understandable representation.
That is, the quaternion is represented as a pivot vector 'axis' and a rotation 'theta' (in radians) about that pivot vector.
If the identity unit quaternion is attempted to be converted to the pivot axis and angle representation it will be set to a zero degree rotation about the axis that was passed in. (Note that any axis will do, since an infinity of axis with rotation of zero satisfy the identity rotation.) If the axis is zero length, then an arbitrary axis will be chosen (z-axis).
[out] | axis | the axis about which the rotation occurs |
[out] | theta | the angle of rotation about the axis in radians |
MQuaternion & setToXAxis | ( | double | theta | ) |
Sets this quaternion to be the rotation about the X axis of theta (in radians).
If the length of the axis is too small the quaternion returned will be the identity quaternion.
[in] | theta | the angle of rotation about the X axis in radians |
MQuaternion & setToYAxis | ( | double | theta | ) |
Sets this quaternion to be the rotation about the Y axis of theta (in radians).
If the length of the axis is too small the quaternion returned will be the identity quaternion.
[in] | theta | the angle of rotation about the Y axis in radians |
MQuaternion & setToZAxis | ( | double | theta | ) |
Sets this quaternion to be the rotation about the Z axis of theta (in radians).
If the length of the axis is too small the quaternion returned will be the identity quaternion.
[in] | theta | the angle of rotation about the Z axis in radians |
MStatus get | ( | double | dest[4] | ) | const |
Extracts the x, y, z, and w components of the quaternion and places them in elements 0, 1, 2, and 3 of the double array passed.
[out] | dest | the array of 4 doubles into which the results are placed. |
double operator[] | ( | unsigned int | i | ) | const |
The index operator.
If its argument is 0 it will return the x component of the quaternion. If its argument is 1 it will return the y component of the quaternion. If its argument is 2 it will return the z component of the quaternion. If its argument is 3 it will return the w component of the quaternion.
[in] | i | value indicating which component to return |
MQuaternion operator+ | ( | const MQuaternion & | other | ) | const |
The quaternion addition operator.
[in] | other | the quaternion to be added to this quaternion |
MQuaternion operator* | ( | const MQuaternion & | other | ) | const |
This quaternion multiplication operator.
Quaternions in Maya multiply on the right (post-multiply) the same as matrices. Many popular quaternion papers (Shoemake) use pre-multiplication where quaternions pre-multiply on the left so you must be aware of this when using quaternions.
In general, if p and q are quaternions, pq != qp, i.e., multiplication does not commute!
[in] | other | the quaternion to be multiplied with this quaternion |
MQuaternion & operator*= | ( | const MQuaternion & | other | ) |
The in place quaternion multiplication operator.
Quaternions in Maya multiply on the right (post-multiply) the same as matrices.
[in] | other | the quaternion to be multiplied with this quaternion |
MQuaternion operator- | ( | const MQuaternion & | other | ) | const |
The quaternion subtraction operator.
[in] | other | the quaternion to be subtracted from this quaternion |
MQuaternion operator- | ( | ) | const |
The unary minus operator.
Negates the value of each of the x, y, z, and w components of the quaternion.
MQuaternion & negateIt | ( | ) |
Performs an in place negation of the quaternion.
The result is a quaternion whose x, y, z, and w values have been negated.
bool operator== | ( | const MQuaternion & | other | ) | const |
The quaternion equality operator.
This returns true if all four of the x, y, z, and w components are identical.
[in] | other | the quaternion to be compared with this quaternion |
bool operator!= | ( | const MQuaternion & | other | ) | const |
The quaternion inequality operator.
This returns false if all four of the x, y, z, and w components are identical.
[in] | other | the quaternion to be compared with this quaternion |
bool isEquivalent | ( | const MQuaternion & | other, |
double | tolerance = kQuaternionEpsilon |
||
) | const |
This method returns true if this quaternion is equal, within some given tolerance, to the other quaternion.
'tolerance' defaults to kQuaternionEpsilon which is 1.0e-10
[in] | other | the quaternion to be compared with this quaternion |
[in] | tolerance | the amount of variation allowed for equivalency |
MQuaternion & scaleIt | ( | double | scale | ) |
Performs an in place scaling of the quaternion.
The result is a quaternion whose x, y, z, and w values have been scaled by the specified amount.
[in] | scale | the amount by which the quaternion should be scaled |
MQuaternion normal | ( | ) | const |
Returns the normal of this quaternion.
The result is a quaternion of unit length.
If the quaternion is zero or has a very small length it will instead be set to the multiplicative identity.
MQuaternion & normalizeIt | ( | ) |
Performs an in place normalization of this quaternion.
The result is a quaternion of unit length.
If the quaternion is zero or has a very small length it will instead be set to the multiplicative identity.
MQuaternion conjugate | ( | ) | const |
Returns the conjugate of this quaternion.
The result is a quaternion whose x, y, and z values have been negated.
MQuaternion & conjugateIt | ( | ) |
Performs an in place conjugation of this quaternion.
The result is a quaternion whose x, y, and z values have been negated.
MQuaternion inverse | ( | ) | const |
Returns the inverse of this quaternion.
MQuaternion & invertIt | ( | ) |
Performs an in place inversion of this quaternion.
MQuaternion log | ( | ) | const |
Returns the natural log of a quaternion.
The precondition for using this method is that the quaternion must be normalized.
Note that the log of a unit quaternion is not necessarily a unit quaternion.
MQuaternion exp | ( | ) | const |
Exponentiates a quaternion that has a scalar part of zero.
The precondition for using this method is that w is zero.
double & operator[] | ( | unsigned int | i | ) |
NO SCRIPT SUPPORT.
The index operator.
If its argument is 0 it will return the x component of the quaternion. If its argument is 1 it will return the y component of the quaternion. If its argument is 2 it will return the z component of the quaternion. If its argument is 3 it will return the w component of the quaternion.
[in] | i | value indicating which component to return |
operator MMatrix | ( | ) | const |
NO SCRIPT SUPPORT.
Casts a quaternion to a matrix.
|
friend |
NO SCRIPT SUPPORT.
[in] | scale | the amount by which the quaternion should be scaled |
[in] | other | the quaternion to which the scale should be applied |
|
friend |
Spherical linear interpolation (abbreviated as slerp) of unit quaternions.
As t goes from 0 to 1, the quaternion returned goes from p to q. The interpolation always takes shortest path (in quaternion space) from p to q.
[in] | p | quaternion to rotate from |
[in] | q | quaternion to rotate to |
[in] | t | interpolation value |
|
friend |
NO SCRIPT SUPPORT.
As t goes from 0 to 1, the quaternion returned goes from p to q. The spin parameter determines how many complete revolutions around the axis will occur as p goes to q. Negative spins will take the "long way" around the great sphere when rotating. (-1 can be used to interpolate using the "long" path on the quaternion sphere without any extra spins.)
[in] | p | quaternion to rotate from |
[in] | q | quaternion to rotate to |
[in] | t | interpolation value |
[in] | spin | the number of complete revolutions around the axis |
|
friend |
NO SCRIPT SUPPORT.
As t goes from 0 to 1, the quaternion returned goes from p to q.
[in] | p | quaternion to rotate from |
[in] | q | quaternion to rotate to |
[in] | t | interpolation value |
[in] | dir | the direction of the interpolation |
|
friend |
NO SCRIPT SUPPORT.
Need to use squadPoint or some other suitable method for finding a and b
[in] | p | quaternion to rotate from |
[in] | a | intermediate squad point |
[in] | b | intermediate squad point |
[in] | q | quaternion to rotate to |
[in] | t | interpolation value |
|
friend |
NO SCRIPT SUPPORT.
Need to use squadPoint or some other suitable method for finding a and b
[in] | p | quaternion to rotate from |
[in] | a | intermediate squad point |
[in] | b | intermediate squad point |
[in] | q | quaternion to rotate to |
[in] | t | interpolation value |
[in] | spin | number of full spins |
|
friend |
NO SCRIPT SUPPORT.
This method uses the average of the tangents of arcs to adjacent points. Therefore, to squad from p to q we need to find a and b in the following manner:
Given: unit quaternion control points we wish to interpolate (q0, q1,..., p-1, p, q, q+1,..., qN)
Want: a, b such that squad(p, a, b, q, t) generates a C1 continuous cubic curve from p to q as we vary t from 0 to 1.
Calculation: a = squadPoint(p-1, p, q); b = squadPoint(p, q, q+1);
Notes: We only need to compute one squadPoint for each segment (except at endpoints) since the next 'a' value is simply our current 'b' value (ie. a(i) = b(i-1) or b(i) = a(i+1)).
[in] | q0 | quaternion from which the squad is computed |
[in] | q1 | quaternion from which the squad is computed |
[in] | q2 | quaternion from which the squad is computed |
|
friend |
NO SCRIPT SUPPORT.
The format used is [x: x, y: y, z: z, w: w].
[in] | os | the ostream to print to |
[in] | q | the quaternion to be printed |