Defining a Quaternion | |
Quaternion () | |
Quaternion (const Vec &axis, double angle) | |
Quaternion (const Vec &from, const Vec &to) | |
Quaternion (double q0, double q1, double q2, double q3) | |
Quaternion (const Quaternion &Q) | |
Quaternion & | operator= (const Quaternion &Q) |
void | setAxisAngle (const Vec &axis, double angle) |
void | setValue (double q0, double q1, double q2, double q3) |
void | setFromRotationMatrix (const float m[3][3]) |
void | setFromRotatedBase (const Vec &X, const Vec &Y, const Vec &Z) |
Accessing values | |
Vec | axis () const |
float | angle () const |
void | getAxisAngle (Vec &axis, float &angle) const |
double | operator[] (int i) const |
double & | operator[] (int i) |
Rotation computations | |
Quaternion & | operator *= (const Quaternion &q) |
Vec | rotate (const Vec &v) const |
Vec | inverseRotate (const Vec &v) const |
Quaternion | operator * (const Quaternion &a, const Quaternion &b) |
Vec | operator * (const Quaternion &q, const Vec &v) |
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 interpolation | |
Quaternion | log () |
Quaternion | exp () |
static Quaternion | slerp (const Quaternion &a, const Quaternion &b, float t, bool allowFlip=true) |
static Quaternion | squad (const Quaternion &a, const Quaternion &tgA, const Quaternion &tgB, const Quaternion &b, float t) |
static double | dot (const Quaternion &a, const Quaternion &b) |
static Quaternion | lnDif (const Quaternion &a, const Quaternion &b) |
static Quaternion | squadTangent (const Quaternion &before, const Quaternion ¢er, const Quaternion &after) |
XML representation | |
Quaternion (const QDomElement &element) | |
QDomElement | domElement (const QString &name, QDomDocument &document) const |
void | initFromDOMElement (const QDomElement &element) |
Output stream | |
std::ostream & | operator<< (std::ostream &o, const qglviewer::Vec &) |
Random Quaternion | |
static Quaternion | randomQuaternion () |
The Quaternion is an appropriate (although not very intuitive) representation for 3D rotations and orientations. Many tools are provided to ease the definition of a Quaternion: see constructors, setAxisAngle(), setFromRotationMatrix(), setFromRotatedBase().
You can apply the rotation represented by the Quaternion to 3D points using rotate() and inverseRotate(). See also the Frame class that represents a coordinate system and provides other conversion functions like Frame::coordinatesOf() and Frame::transformOf().
You can apply the Quaternion rotation to the OpenGL matrices with code like:
Quaternion q; glMultMatrixd(q.matrix()); // or using glRotate instead: glRotate(q.angle()*180.0/M_PI, q.axis().x, q.axis().y, q.axis().z);
Quaternion is part of the qglviewer
namespace, specify qglviewer::Quaternion
or use the qglviewer namespace:
using namespace qglviewer;
The internal representation of a Quaternion corresponding to a rotation around axis axis
, with an angle alpha
is made of four doubles q[i]:
Note that certain implementations place the cosine term in first position (instead of last here).
The Quaternion is always normalized, so that its inverse() is actually its conjugate.
See also the Vec and Frame class documentations.
|
Default constructor, builds an identity rotation. |
|
Constructor from rotation axis (non null) and angle (in radians). See also setAxisAngle(). |
|
Constructs a Quaternion that will rotate from the
Note that this rotation is not uniquely defined. The selected axis is usually orthogonal to |
|
Constructor from the four values of a Quaternion. First three values are axis*sin(angle/2) and last one is cos(angle/2).
|
|
Copy constructor. |
|
Constructs a Quaternion from a If one of these attributes is missing or is not a number, a warning is displayed and the associated value is respectively set to 0, 0, 0 and 1 (identity Quaternion). See also domElement() and initFromDOMElement(). |
|
Returns the angle (in radians) of the rotation represented by the Quaternion. This value is always in the range [0-pi]. Larger rotational angles are obtained by inverting the axis() direction. See also axis() and getAxisAngle(). |
|
Returns the normalized axis direction of the rotation represented by the Quaternion. It is null for an identity Quaternion. See also angle() and getAxisAngle(). |
|
Returns an XML
When output to a file, the resulting QDomElement will look like: <name q0=".." q1=".." q2=".." q3=".." />
Use initFromDOMElement() to restore the Quaternion state from the resulting See the Vec::domElement() documentation for a complete QDomDocument creation and saving example. See also Frame::domElement(), Camera::domElement(), KeyFrameInterpolator::domElement()... |
|
Returns the "dot" product of |
|
Returns the exponential of the Quaternion. See also log(). |
|
Returns the axis vector and the angle (in radians) of the rotation represented by the Quaternion. See the axis() and angle() documentations. |
|
Same as getInverseMatrix(), but with a |
|
Fills Use inverseMatrix() if you do not need to store this matrix and simply want to alter the current OpenGL matrix. See also getMatrix(). |
|
|
|
Same as getMatrix(), but with a |
|
Fills Use matrix() if you do not need to store this matrix and simply want to alter the current OpenGL matrix. See also getInverseMatrix() and Frame::getMatrix(). |
|
Fills See also getInverseRotationMatrix().
|
|
Restores the Quaternion state from a
The See also the Quaternion(const QDomElement&) constructor. |
|
Returns the inverse Quaternion (inverse rotation). Result has a negated axis() direction and the same angle(). A composition (see operator*()) of a Quaternion and its inverse() results in an identity function. Use invert() to actually modify the Quaternion. |
|
Returns the associated 4x4 OpenGL inverse rotation matrix. This is simply the matrix() of the inverse().
|
|
Returns the image of rotate() performs an inverse transformation. Same as inverse().rotate(v). |
|
Inverses the Quaternion (same rotation angle(), but negated axis()). 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.
Use See also getMatrix(), getRotationMatrix() and inverseMatrix().
|
|
Negates all the coefficients of the Quaternion. This results in an other representation of the same rotation (opposite rotation angle, but with a negated axis direction: the two cancel out). However, note that the results of axis() and angle() are unchanged after a call to this method since angle() always returns a value in [0,pi]. This method is mainly useful for Quaternion interpolation, so that the spherical interpolation takes the shortest path on the unit sphere. See slerp() for details. |
|
Normalizes the Quaternion coefficients. This method should not need to be called since we only deal with unit Quaternions. This is however useful to prevent numerical drifts, especially with small rotational increments. |
|
Quaternion rotation is composed with
See operator*(), since this is equivalent to
|
|
Output stream operator. Enables debugging code like: Quaternion rot(...); cout << "Rotation=" << rot << endl; |
|
Equal operator. |
|
Bracket operator returning an l-value. |
|
Bracket operator, with a constant return value. |
|
Returns a random unit Quaternion. You can create a randomly directed unit vector using: Vec randomDir = Quaternion::randomQuaternion() * Vec(1.0, 0.0, 0.0); // or any other Vec
|
|
Returns the image of See also inverseRotate() and operator*(const Quaternion&, const Vec&). |
|
Sets the Quaternion as a rotation of axis
|
|
Sets the Quaternion from the three rotated vectors of an orthogonal basis. The three vectors do not have to be normalized but must be orthogonal.
Quaternion q; q.setFromRotatedBase(X, Y, Z); // Now q.rotate(Vec(1,0,0)) == X and q.inverseRotate(X) == Vec(1,0,0) // Same goes for Y and Z with Vec(0,1,0) and Vec(0,0,1). See also setFromRotationMatrix() and Quaternion(const Vec&, const Vec&). |
|
Set the Quaternion from a (supposedly correct) 3x3 rotation matrix. The matrix is expressed in European format: its three columns are the images by the rotation of the three vectors of an orthogonal basis. Note that OpenGL uses a symmetric representation for its matrices. setFromRotatedBase() sets a Quaternion from the three axis of a rotated frame. It actually fills the three columns of a matrix with these rotated basis vectors and calls this method. |
|
Sets the Quaternion value. See the Quaternion(double, double, double, double) constructor documentation. |
|
Returns the slerp interpolation of Quaternions
When |
|
Returns the slerp interpolation of the two Quaternions
The resulting Quaternion is "between"
Use squadTangent() to define the Quaternion tangents |
|
Returns a tangent Quaternion for Useful for smooth spline interpolation of Quaternion with squad() and slerp(). |
|
Returns the image of Same as q.rotate(v). See rotate() and inverseRotate(). |
|
Returns the composition of the
The order is important. When applied to a Vec v'= (a*b) * v = a * (b*v) Note that a*b usually differs from b*a.
|