#include <quaternion.h>
Defining a Quaternion | |
Quaternion () | |
Default Quaternion, a null rotation. | |
Quaternion (const Vec &axis, double angle) | |
Simple constructor with any axis and angle (in radians). | |
Quaternion (const Vec &v, double sin_ha, double cos_ha) | |
Constructor with normalized axis, cos & sin of half angle. | |
Quaternion (double q0, double q1, double q2, double q3) | |
Constructor from the values (v*sin(a/2), cos(a/2)) of a Quaternion. | |
Quaternion (const Vec &from, const Vec &to) | |
Constructs a Quaternion that will rotate from the from direction to the to direction. | |
Quaternion & | operator= (const Quaternion &Q) |
Equal operator. | |
Quaternion (const Quaternion &Q) | |
Copy constructor. | |
void | setAxisAngle (const Vec &v, double angle) |
To reset a Quaternion to the rotation of axis v and angle angle (in radians). | |
void | setValue (double q0, double q1, double q2, double q3) |
Set the current Quaternion value. | |
void | setFromRotationMatrix (const float m[3][3]) |
void | setFromRotatedBase (const Vec &X, const Vec &Y, const Vec &Z) |
Access values | |
Vec | axis () const |
float | angle () const |
void | getAxisAngle (Vec &axis, float &angle) const |
double | operator[] (int i) const |
Bracket operator, with a constant return value. | |
double & | operator[] (int i) |
Bracket operator, returns an l-value. | |
Calculus | |
Quaternion & | operator *= (const Quaternion &quat) |
Vec | inverseRotate (const Vec &v) const |
Vec v is applied the inverse Quaternion rotation (inverseRotate() * rotate() is the identity). | |
Vec | rotate (const Vec &v) const |
Vec v is rotated by the Quaternion rotation (see also inverseRotate()). | |
const Quaternion | operator * (const Quaternion &a, const Quaternion &b) |
const Vec | operator * (const Quaternion &a, const Vec &b) |
Same as a.rotate(b). | |
Inversion | |
Quaternion | inverse () const |
void | invert () |
void | negate () |
double | normalize () |
Associated matrix | |
const GLdouble * | matrix () const |
void | getMatrix (GLdouble m[4][4]) const |
void | getMatrix (GLdouble m[16]) const |
void | getRotationMatrix (float m[3][3]) const |
const GLdouble * | inverseMatrix () const |
void | getInverseMatrix (GLdouble m[4][4]) const |
void | getInverseMatrix (GLdouble m[16]) const |
void | getInverseRotationMatrix (float m[3][3]) const |
Slerp rotation interpolation | |
Quaternion | log () |
Quaternion | exp () |
Quaternion | slerp (const Quaternion &a, const Quaternion &b, float t, bool allowFlip=true) |
Quaternion | squad (const Quaternion &a, const Quaternion &tgA, const Quaternion &tgB, const Quaternion &b, float t) |
double | dot (const Quaternion &a, const Quaternion &b) |
Quaternion | lnDif (const Quaternion &a, const Quaternion &b) |
Quaternion | squadTangent (const Quaternion &a, const Quaternion &b, const Quaternion &c) |
XML representation | |
Quaternion (const QDomElement &e) | |
QDomElement | domElement (const QString &name, QDomDocument &doc) const |
void | initFromDOMElement (const QDomElement &e) |
Random orientation | |
Quaternion | randomOrientation () |
A Quaternion is a clean representation of a 3D rotation matrix or of an orientation. In this implementation, the Quaternion are supposed to be normalized, so that the inverse() is actually a conjugate function.
Many tools are provided define a 3D rotation (constructors, setAxisAngle(), setFromRotationMatrix(), setFromRotatedBase()...). Apply the rotation to 3D points using rotate() and inverseRotate(). Also consider the Frame coordinate system conversion functions like Frame::coordinatesOf() and Frame::coordinatesOfFrom().
The Quaternion corresponding to a rotation vector v
, with an angle alpha
is :
{q[0],q[1],q[2]} = sin(alpha/2) * {v[0],v[1],v[2]} q[3] = cos(alpha/2)
You can use the Quaternion in OpenGL functions with code like this:
Quaternion is a QGLViewer internal class. It is part of the qglviewer
namespace. You can use it in your programs by specifying qglviewer::Quaternion
, or by using the qglviewer namespace :
See also the Vec and the Frame documentations.using namespace qglviewer;
|
Constructor from the values (v*sin(a/2), cos(a/2)) of a Quaternion.
|
|
Returns the angle (in radians) of the rotation represented by the Quaternion. See also axis() and getAxisAngle().
|
|
Returns the axis of the rotation represented by the Quaternion. The axis may be null for an identity rotation. See also angle() and getAxisAngle(). |
|
Creates an XML QDomElement that represents the Quaternion. Use initFromDOMElement() to restore the Quaternion state from the resulting domElement. When saved to a file (see Qt::QDomDocument documentation) it will create a line like:
See also Vec::domElement(), Camera::domElement(), KeyFrameInterpolator::domElement()... |
|
Return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3]. See also negate() and slerp(). |
|
Returns the exponential of the Quaternion. See also log(). |
|
Returns the axis and the angle (in radians) of the rotation represented by the Quaternion. See also axis() and angle(). |
|
double[16] parameter version of inverseMatrix(). See also getMatrix(). |
|
double[4][4] parameter version of inverseMatrix(). See also getMatrix(). |
|
|
|
double[16] parameter version of matrix(). See also getInverseMatrix() and Frame::getMatrix(). |
|
double[4][4] parameter version of matrix(). See also getInverseMatrix() and Frame::getMatrix(). |
|
|
|
Restore the Quaternion state from a |
|
Returns the inverse of the Quaternion (axis() is negated), which represents the opposite orientation. The original Quaternion is not modified. Use invert() to actually modify the Quaternion. |
|
Returns the associated 4x4 OpenGL inverse rotation matrix. This is simply the matrix() of the inverse().
|
|
Inverse the Quaternion (same rotation angle, but opposite axis). The new orientation is the inverse (in the mathematical sense) of the previous one. The rotation represented by this Quaternion is now the inverse rotation. See also inverse(). |
|
Returns log(a. inverse() * b). Useful for squadTangent(). |
|
Returns the logarithm of the Quaternion. See also exp(). |
|
Returns the Quaternion associated 4x4 OpenGL rotation matrix. Can be used with
See also getMatrix(), getRotationMatrix() and inverseMatrix().
|
|
Negate all the coefficients of the Quaternion. The axis and angle are negated. However, the result of axis() and angle() are unchanged, as it is just an other representation of the same Quaternion (see angle(), which always returns a value in [0,pi]). Useful for Quaternion interpolation, so that the spherical interpolation takes the shortest path. See also slerp(), squad(), dot(). |
|
Normalize the Quaternion. Should not need to be called as we only deal with unit Quaternion. Useful to prevent numerical drifts, especially with small rotational increments. |
|
Quaternion is composed with
|
|
Returns a random unit Quaternion. A randomly directed unit vector can then be computed using :
|
|
Same as setFromRotationMatrix(), but the input are the three orthogonal axis of a rotated basis: |
|
Set the Quaternion from a (supposedly correct) 3x3 rotation matrix. Use setFromRotatedBase() a fill the three columns of the matrix with your basis vectors in order to to set a Quaternion from the three axis of a rotated frame. |
|
Returns the slerp interpolation of Quaternion
When |
|
Returns the slerp interpolation of the two Quaternion |
|
Returns a tangent Quaternion, which enables a smooth spline interpolation of Quaternion with squad(). |
|
Returns the composition of the two rotations (mind the order !).
|