Defining a Quaternion | |
Quaternion () | |
Default Quaternion, a null rotation. | |
Quaternion (const Vec &axis, const double angle) | |
Simple constructor with any axis and angle (in radians). | |
Quaternion (const Vec &v, const double sin_ha, const double cos_ha) | |
Constructor with normalized axis, cos & sin of half angle. | |
Quaternion (const double q0, const double q1, const double q2, const double q3) | |
Constructor from the values 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, const double angle) |
To reset a Quaternion to the rotation of axis v and angle angle (in radians). | |
void | setValue (const double q0, const double q1, const double q2, const 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 &q) |
Quaternion is composed with q . | |
Vec | inverseRotate (const Vec &v) const |
Vec v is applied the inverse Quaternion rotation (inverse of rotate()). | |
Vec | rotate (const Vec &v) const |
Vec v is applied the Quaternion rotation (see also inverseRotate()). | |
const Quaternion | operator * (const Quaternion &a, const Quaternion &b) |
Returns the composition of the two rotations (mind the order !). | |
const Vec | operator * (const Quaternion &a, const Vec &b) |
Same as a.rotate(b). | |
Inversion | |
Quaternion | inverse () const |
Returns the inverse of the Quaternion. The Quaternion is not modified. See invert(). | |
void | invert () |
Inverse the Quaternion (same rotation angle, but opposite axis). See also inverse(). | |
void | negate () |
double | normalize () |
Normalize the Quaternion. Should not need to be called as we only deal with unit Quaternion. | |
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 |
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 | |
QDomElement | domElement (const QString &name, QDomDocument &doc) const |
void | initFromDOMElement (const QDomElement &de) |
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)
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 :
using namespace qglviewer;
|
Default Quaternion, a null rotation.
|
|
Simple constructor with any axis and angle (in radians).
|
|
Constructor with normalized axis, cos & sin of half angle.
|
|
Constructor from the values of a Quaternion.
|
|
Constructs a Quaternion that will rotate from the
|
|
Copy constructor.
|
|
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. QDomDocument doc("myDocument"); Quaternion sunQuat; // ... anyNode.addElement(sunQuat.domElement("sunOrientation", doc)); // ... 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 matrix(). See also Frame::getMatrix(). |
|
double[4][4] parameter version of matrix(). See also Frame::getMatrix(). |
|
|
|
Restore the Quaternion state from a QDomElement created by domElement(). The QDomElement must contain the q0, q1 , q2 and q3 attributes, otherwise these fields are set to 0.0, 0.0, 0.0, 1.0 (identity Quaternion) . |
|
Returns the inverse of the Quaternion. The Quaternion is not modified. See invert().
|
|
Vec v is applied the inverse Quaternion rotation (inverse of rotate()).
|
|
Inverse the Quaternion (same rotation angle, but opposite axis). See also inverse().
|
|
Returns log(a.inverse() * b). Useful for squadTangent(). |
|
Returns the logarithm of the Quaternion. See also exp(). |
|
Returns the associated 4x4 OpenGL rotation matrix. Can be used with Vec From,To; // Set the From and To directions // Computes a Quaternion which transform From in To Quaternion q(From, To); // Rotates the current openGL matrix. glMultMatrixd(q.matrix());
|
|
Negate the coefficients of the Quaternion. axis() and angle() are unchanged, it is just an other representation of the same Quaternion. Useful for Quaternion interpolation, so that the 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.
|
|
Quaternion is composed with
|
|
Equal operator.
|
|
Bracket operator, returns an l-value.
|
|
Bracket operator, with a constant return value.
|
|
Returns a random unit Quaternion. A randomly directed unit vector can then be computed using : Vec randomDir = Quaternion::randomOrientation() * Vec(1.0, 0.0, 0.0);
|
|
Vec
|
|
To reset a Quaternion to the rotation of axis
|
|
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. |
|
Set the current Quaternion value.
|
|
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(). |
|
Same as a.rotate(b).
|
|
Returns the composition of the two rotations (mind the order !).
|