Unit quaternions, known as versors, provide a convenient mathematical notation for representing spatial orientations and rotations of elements in three dimensional space (3D rotations). This is a generalization of the use of unit complex numbers for 2D rotations. Specifically, quaternions encode information about an axis-angle rotation about an arbitrary axis. Rotation and orientation quaternions have applications in computer graphics, Presented at SIGGRAPH '85. computer vision, robotics,J. M. McCarthy, 1990, Introduction to Theoretical Kinematics, MIT Press navigation, molecular dynamics, flight dynamics,Amnon Katz (1996) Computational Rigid Vehicle Dynamics, Krieger Publishing orbital mechanics of satellites,J. B. Kuipers (1999) Quaternions and rotation Sequences: a Primer with Applications to Orbits, Aerospace, and Virtual Reality, Princeton University Press and crystallographic texture analysis.
When used to represent rotation, unit quaternions are also called rotation quaternions as they represent the 3D rotation group. When used to represent an orientation or attitude (body rotation relative to a reference coordinate system), they are called orientation quaternions or attitude quaternions. A spatial rotation in the amount of radians about a fixed unit axis that denotes the Euler axis is given by the quaternion , where and .
Compared to rotation matrices, quaternions are more compact, efficient, and numerically stable. Compared to Euler angles, they are simpler to compose. However, they are not as intuitive and easy to understand and, due to the periodic nature of sine and cosine, rotation angles differing precisely by the natural period will be encoded into identical quaternions and recovered angles in radians will be limited to .
Using quaternions as rotations
In 3-dimensional space, according to Euler's rotation theorem, any rotation or sequence of rotations of a rigid body or coordinate system about a fixed point is equivalent to a single rotation by a given angle about a fixed axis (called the Euler axis) that runs through the fixed point. Euclidean and non-Euclidean Geometry. Patrick J. Ryan, Cambridge University Press, Cambridge, 1987. The Euler axis is typically represented by a unit vector ( in the picture). Therefore, any rotation in three dimensions can be represented as a vector and an angle .
Quaternions give a simple way to encode this axis–angle representation using four real numbers, and can be used to apply (calculate) the corresponding rotation to a position vector , representing a point relative to the origin in .I.L. Kantor. Hypercomplex numbers, Springer-Verlag, New York, 1989.
Euclidean vectors such as or can be rewritten as or , where , , are unit vectors representing the three Cartesian axes (traditionally , , ), and also obey the multiplication rules of the fundamental quaternion units by interpreting the Euclidean vector as the vector part of the pure quaternion .
A rotation of angle around the axis defined by the unit vector
can be represented by conjugation by a unit quaternion . Since the quaternion product gives 1, using the Taylor series of the exponential function, the extension of Euler's formula results:
It can be shownAndrew J. Hanson. Visualizing Quaternions, Morgan Kaufmann Publishers, Amsterdam, 2006. that the desired rotation can be applied to an ordinary vector in 3-dimensional space, considered as the vector part of the pure quaternion , by evaluating the conjugation of by , given by:
using the Hamilton product, where the vector part of the pure quaternion is the new position vector of the point after the rotation. In a programmatic implementation, the conjugation is achieved by constructing a pure quaternion whose vector part is , and then performing the quaternion conjugation. The vector part of the resulting pure quaternion is the desired vector . Clearly, provides a linear transformation of the quaternion space to itself;J.H. Conway and D.A. Smith. On Quaternions and Octonions, A.K. Peters, Natick, MA, 2003. also, since is unitary, the transformation is an isometry. Also, and so leaves vectors parallel to invariant. So, by decomposing as a vector parallel to the vector part of and a vector normal to the vector part of and showing that the application of to the normal component of rotates it, the claim is shown. So let be the component of orthogonal to the vector part of and let . It turns out that the vector part of is given by . The conjugation of by can be expressed with fewer arithmetic operations as:
A geometric fact independent of quaternions is the existence of a two-to-one mapping from physical rotations to rotational transformation matrices. If 0 ⩽ ⩽ , a physical rotation about by and a physical rotation about by both achieve the same final orientation by disjoint paths through intermediate orientations. By inserting those vectors and angles into the formula for above, one finds that if represents the first rotation, represents the second rotation. This is a geometric proof that conjugation by and by must produce the same rotational transformation matrix. That fact is confirmed algebraically by noting that the conjugation is quadratic in , so the sign of cancels, and does not affect the result. (See 2:1 mapping of SU(2) to SO(3)) If both rotations are a half-turn , both and will have a real coordinate equal to zero. Otherwise, one will have a positive real part, representing a rotation by an angle less than , and the other will have a negative real part, representing a rotation by an angle greater than .
Mathematically, this operation carries the set of all "pure" quaternions (those with real part equal to zero)—which constitute a 3-dimensional space among the quaternions—into itself, by the desired rotation about the axis , by the angle . (Each real quaternion is carried into itself by this operation. But for the purpose of rotations in 3-dimensional space, we ignore the real quaternions.)
The rotation is clockwise if our line of sight points in the same direction as .
In this instance, is a unit quaternion and
It follows that conjugation by the product of two quaternions is the composition of conjugations by these quaternions: If and are unit quaternions, then rotation (conjugation) by is , which is the same as rotating (conjugating) by and then by . The scalar component of the result is necessarily zero.
The quaternion inverse of a rotation is the opposite rotation, since . The square of a quaternion rotation is a rotation by twice the angle around the same axis. More generally is a rotation by times the angle around the same axis as . This can be extended to arbitrary real , allowing for smooth interpolation between spatial orientations; see Slerp.
Two rotation quaternions can be combined into one equivalent quaternion by the relation:
in which corresponds to the rotation followed by the rotation . Thus, an arbitrary number of rotations can be composed together and then applied as a single rotation. (Note that quaternion multiplication is not commutative.)
Example conjugation operation
Conjugating by refers to the operation .
Consider the rotation around the axis , with a rotation angle of 120°, or radians.
The length of is , the half angle is (60°) with cosine , () and sine , (). We are therefore dealing with a conjugation by the unit quaternion
If is the rotation function,
It can be proven that the inverse of a unit quaternion is obtained simply by changing the sign of its imaginary components. As a consequence,
and
This can be simplified, using the ordinary rules for quaternion arithmetic, to
As expected, the rotation corresponds to keeping a cube held fixed at one point, and rotating it 120° about the long diagonal through the fixed point (observe how the three axes are permuted cyclically).
Quaternion-derived rotation matrix A quaternion rotation (with ) can be algebraically manipulated into a matrix rotation , where is the rotation matrix given by:
Here and if is a unit quaternion, .
This can be obtained by using vector calculus and linear algebra if we express and as scalar and vector parts and use the formula for the multiplication operation in the equation . If we write as , as and as , where , our equation turns into . By using the formula for multiplication of two quaternions that are expressed as scalar and vector parts,
this equation can be rewritten as
where denotes the outer product, is the identity matrix and is the transformation matrix that when multiplied from the right with a vector gives the cross product .
Since , we can identify as , which upon expansion should result in the expression written in matrix form above.
Recovering the axis-angle representation
The expression rotates any vector quaternion around an axis given by the vector by the angle , where and depends on the quaternion .
and can be found from the following equations:
where is the two-argument arctangent. While works, it is numerically unstable (inaccurate) near for numbers with finite precision.
Care should be taken when the quaternion approaches a scalar, since due to degeneracy the axis of an identity rotation is not well-defined.
The composition of spatial rotations A benefit of the quaternion formulation of the composition of two rotations and is that it yields directly the rotation axis and angle of the composite rotation .
Let the quaternion associated with a spatial rotation be constructed from its rotation axis with the rotation angle around this axis. The associated quaternion is given by
Then the composition of the rotation with is the rotation with rotation axis and angle defined by the product of the quaternions
that is
Expand this product to obtain
Divide both sides of this equation by the identity, which is the law of cosines on a sphere,
and compute
This is Rodrigues' rotation formula for the axis of a composite rotation defined in terms of the axes of the two rotations. He derived this formula in 1840 (see page 408).Translated in
The three rotation axes , , and form a spherical triangle and the dihedral angles between the planes formed by the sides of this triangle are defined by the rotation angles. HamiltonWilliam Rowan Hamilton (1844 to 1850) On quaternions or a new system of imaginaries in algebra, Philosophical Magazine, link to David R. Wilkins collection at Trinity College, Dublin presented the component form of these equations showing that the quaternion product computes the third vertex of a spherical triangle from two given vertices and their associated arc-lengths, which is also defines an algebra for points in Elliptic geometry.
Axis–angle composition
The normalized rotation axis, removing the from the expanded product, leaves the vector which is the rotation axis, times some constant. Care should be taken normalizing the axis vector when is or where the vector is near ; which is identity, or 0 rotation around any axis.
Or with angle addition trigonometric substitutions...
finally normalizing the rotation axis: or .
Differentiation with respect to the rotation quaternion
The rotated quaternion needs to be differentiated with respect to the rotating quaternion , when the rotation is estimated from numerical optimization. The estimation of rotation angle is an essential procedure in 3D object registration or camera calibration. For unitary and pure imaginary , that is for a rotation in 3D space, the derivatives of the rotated quaternion can be represented using matrix calculus notation as
A derivation can be found in.
Background
Quaternions
The complex numbers can be defined by introducing an abstract symbol which satisfies the usual rules of algebra and additionally the rule . This is sufficient to reproduce all of the rules of complex number arithmetic: for example: