quaternions and spatial rotation
   HOME

TheInfoList



OR:

Unit
quaternion In mathematics, the quaternion number system extends the complex numbers. Quaternions were first described by the Irish mathematician William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space. The algebra of quater ...
s, known as ''versors'', provide a convenient
mathematical Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
notation for representing spatial orientations and
rotation Rotation or rotational/rotary motion is the circular movement of an object around a central line, known as an ''axis of rotation''. A plane figure can rotate in either a clockwise or counterclockwise sense around a perpendicular axis intersect ...
s of elements in three dimensional space. Specifically, they encode information about an axis-angle rotation about an arbitrary axis. Rotation and orientation quaternions have applications in
computer graphics Computer graphics deals with generating images and art with the aid of computers. Computer graphics is a core technology in digital photography, film, video games, digital art, cell phone and computer displays, and many specialized applications. ...
, Presented at
SIGGRAPH SIGGRAPH (Special Interest Group on Computer Graphics and Interactive Techniques) is an annual conference centered around computer graphics organized by ACM, starting in 1974 in Boulder, CO. The main conference has always been held in North ...
'85.
computer vision Computer vision tasks include methods for image sensor, acquiring, Image processing, processing, Image analysis, analyzing, and understanding digital images, and extraction of high-dimensional data from the real world in order to produce numerical ...
,
robotics Robotics is the interdisciplinary study and practice of the design, construction, operation, and use of robots. Within mechanical engineering, robotics is the design and construction of the physical structures of robots, while in computer s ...
,
navigation Navigation is a field of study that focuses on the process of monitoring and controlling the motion, movement of a craft or vehicle from one place to another.Bowditch, 2003:799. The field of navigation includes four general categories: land navig ...
,
molecular dynamics Molecular dynamics (MD) is a computer simulation method for analyzing the Motion (physics), physical movements of atoms and molecules. The atoms and molecules are allowed to interact for a fixed period of time, giving a view of the dynamics ( ...
,
flight dynamics Flight dynamics in aviation and spacecraft, is the study of the performance, stability, and control of vehicles flight, flying through the air or in outer space. It is concerned with how forces acting on the vehicle determine its velocity and at ...
,
orbital mechanics Orbital mechanics or astrodynamics is the application of ballistics and celestial mechanics to rockets, satellites, and other spacecraft. The motion of these objects is usually calculated from Newton's laws of motion and the law of universal ...
of
satellite A satellite or an artificial satellite is an object, typically a spacecraft, placed into orbit around a celestial body. They have a variety of uses, including communication relay, weather forecasting, navigation ( GPS), broadcasting, scient ...
s, and crystallographic texture analysis. When used to represent rotation, unit quaternions are also called rotation quaternions as they represent the
3D rotation group In mechanics and geometry, the 3D rotation group, often denoted SO(3), is the group of all rotations about the origin of three-dimensional Euclidean space \R^3 under the operation of composition. By definition, a rotation about the origin is ...
. When used to represent an orientation (rotation relative to a reference coordinate system), they are called orientation quaternions or attitude quaternions. A spatial rotation around a fixed point of \theta radians about a unit axis (X,Y,Z) that denotes the ''Euler axis'' is given by the quaternion (C, X \, S, Y \, S, Z \, S), where C = \cos(\theta/2) and S=\sin(\theta/2). Compared to rotation matrices, quaternions are more compact, efficient, and numerically stable. Compared to
Euler angles The Euler angles are three angles introduced by Leonhard Euler to describe the Orientation (geometry), orientation of a rigid body with respect to a fixed coordinate system.Novi Commentarii academiae scientiarum Petropolitanae 20, 1776, pp. 189� ...
, they are simpler to compose. However, they are not as intuitive and easy to understand and, due to the periodic nature of
sine In mathematics, sine and cosine are trigonometric functions of an angle. The sine and cosine of an acute angle are defined in the context of a right triangle: for the specified angle, its sine is the ratio of the length of the side opposite th ...
and cosine, rotation angles differing precisely by the natural period will be encoded into identical quaternions and recovered angles in
radian The radian, denoted by the symbol rad, is the unit of angle in the International System of Units (SI) and is the standard unit of angular measure used in many areas of mathematics. It is defined such that one radian is the angle subtended at ...
s will be limited to ,2\pi/math>.


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 \theta about a fixed axis (called the ''Euler axis'') that runs through the fixed point. The Euler axis is typically represented by a
unit vector In mathematics, a unit vector in a normed vector space is a Vector (mathematics and physics), vector (often a vector (geometry), spatial vector) of Norm (mathematics), length 1. A unit vector is often denoted by a lowercase letter with a circumfle ...
 \vec (\hat in the picture). Therefore, any rotation in three dimensions can be represented as a
vector Vector most often refers to: * Euclidean vector, a quantity with a magnitude and a direction * Disease vector, an agent that carries and transmits an infectious pathogen into another living organism Vector may also refer to: Mathematics a ...
 \vec and an angle \theta. 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 In geometry, a position or position vector, also known as location vector or radius vector, is a Euclidean vector that represents a point ''P'' in space. Its length represents the distance in relation to an arbitrary reference origin ''O'', and ...
, representing a point relative to the origin in .
Euclidean vector In mathematics, physics, and engineering, a Euclidean vector or simply a vector (sometimes called a geometric vector or spatial vector) is a geometric object that has magnitude (or length) and direction. Euclidean vectors can be added and scal ...
s 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 \theta around the axis defined by the unit vector : \mathbf = (u_x, u_y, u_z) = u_x\mathbf + u_y\mathbf + u_z\mathbf can be represented by
conjugation Conjugation or conjugate may refer to: Linguistics *Grammatical conjugation, the modification of a verb from its basic form *Emotive conjugation or Russell's conjugation, the use of loaded language Mathematics *Complex conjugation, the change o ...
by a unit quaternion . Since the quaternion product \ (0 + u_x\mathbf + u_y\mathbf + u_z\mathbf)(0 - u_x\mathbf - u_y\mathbf - u_z\mathbf) gives 1, using the
Taylor series In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor ser ...
of the exponential function, the extension of
Euler's formula Euler's formula, named after Leonhard Euler, is a mathematical formula in complex analysis that establishes the fundamental relationship between the trigonometric functions and the complex exponential function. Euler's formula states that, for ...
results: : \mathbf = e^ = \cos \frac + (u_x\mathbf + u_y\mathbf + u_z\mathbf) \sin \frac = \cos \frac + \mathbf u \sin \frac It can be shown that the desired rotation can be applied to an ordinary vector \mathbf = (p_x, p_y, p_z) = p_x\mathbf + p_y\mathbf + p_z\mathbf in 3-dimensional space, considered as the vector part of the pure quaternion \mathbf, by evaluating the
conjugation Conjugation or conjugate may refer to: Linguistics *Grammatical conjugation, the modification of a verb from its basic form *Emotive conjugation or Russell's conjugation, the use of loaded language Mathematics *Complex conjugation, the change o ...
of  by , given by: : L(\mathbf) := \mathbf \mathbf \mathbf^ = (0, \mathbf r), : \mathbf r = (\cos^2\frac-\sin^2\frac, , \mathbf u, , ^2)\mathbf p + 2\sin^2\frac (\mathbf u \cdot \mathbf p)\mathbf u + 2\cos\frac\sin\frac(\mathbf u \times \mathbf p), 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, L provides a linear transformation of the quaternion space to itself; also, since \mathbf q is unitary, the transformation is an isometry. Also, L(\mathbf q) = \mathbf q and so L leaves vectors parallel to \mathbf q invariant. So, by decomposing \mathbf p as a vector parallel to the vector part (u_x, u_y, u_z)\sin \frac of \mathbf q and a vector normal to the vector part of \mathbf q and showing that the application of L to the normal component of \mathbf p rotates it, the claim is shown. So let \mathbf n be the component of \mathbf p orthogonal to the vector part of \mathbf q and let \mathbf n_T = \mathbf n \times \mathbf u . It turns out that the vector part of L(0, \mathbf n) is given by :\left(\cos^2\frac -\sin^2\frac\right) \mathbf + 2 \left(\cos\frac\sin\frac \right)\mathbf_T = \cos\theta \mathbf + \sin\theta \mathbf_T. The conjugation of by can be expressed with fewer arithmetic operations as: : \mathbf = \mathbf + 2\cos\frac\sin\frac(\mathbf u \times \mathbf p) + 2 \sin^2\frac \mathbf u \times (\mathbf u \times \mathbf p) . A geometric fact independent of quaternions is the existence of a two-to-one mapping from physical rotations to rotational transformation matrices. If 0 ⩽ \theta2\pi, a physical rotation about \vec by \theta and a physical rotation about -\vec by 2\pi-\theta 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 (\theta=\pi), 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 \pi, and the other will have a negative real part, representing a rotation by an angle greater than \pi. 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 \vec. In this (which?) instance, is a unit quaternion and : \mathbf^ = e^ = \cos \frac - (u_x\mathbf + u_y\mathbf + u_z\mathbf) \sin \frac . 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 :\mathbf \vec (\mathbf)^ = \mathbf \vec \mathbf^ \mathbf^ = \mathbf (\mathbf \vec \mathbf^) \mathbf^, 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 \mathbf^ (\mathbf \vec \mathbf^) \mathbf = \vec. 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: : \mathbf' = \mathbf_2 \mathbf_1 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 In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Perhaps most familiar as a pr ...
.)


Example conjugation operation

''Conjugating'' ''by'' refers to the operation . Consider the rotation around the axis \vec = \mathbf + \mathbf + \mathbf, with a rotation angle of 120°, or  
radian The radian, denoted by the symbol rad, is the unit of angle in the International System of Units (SI) and is the standard unit of angular measure used in many areas of mathematics. It is defined such that one radian is the angle subtended at ...
s. :\alpha = \frac The length of \vec is , the half angle is (60°) with
cosine In mathematics, sine and cosine are trigonometric functions of an angle. The sine and cosine of an acute angle are defined in the context of a right triangle: for the specified angle, its sine is the ratio of the length of the side opposite that ...
, () and
sine In mathematics, sine and cosine are trigonometric functions of an angle. The sine and cosine of an acute angle are defined in the context of a right triangle: for the specified angle, its sine is the ratio of the length of the side opposite th ...
, (). We are therefore dealing with a conjugation by the unit quaternion :\begin u &= \cos\frac + \sin\frac\cdot \frac\vec\\ &= \cos \frac + \sin \frac\cdot \frac\vec\\ &= \frac + \frac\cdot \frac\vec\\ &= \frac + \frac\cdot \frac\\ &= \frac \end If is the rotation function, :f(a\mathbf + b\mathbf + c\mathbf) = u (a\mathbf + b\mathbf + c\mathbf) u^ 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, :u^ = \dfrac and :f(a\mathbf + b\mathbf + c\mathbf) = \dfrac(a\mathbf + b\mathbf + c\mathbf) \dfrac This can be simplified, using the ordinary rules for quaternion arithmetic, to :f(a\mathbf + b\mathbf + c\mathbf) = c\mathbf + a\mathbf + b\mathbf As expected, the rotation corresponds to keeping a
cube A cube or regular hexahedron is a three-dimensional space, three-dimensional solid object in geometry, which is bounded by six congruent square (geometry), square faces, a type of polyhedron. It has twelve congruent edges and eight vertices. It i ...
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 \mathbf = \mathbf \mathbf \mathbf^ (with \mathbf = q_r + q_i \mathbf + q_j \mathbf + q_k \mathbf) can be algebraically manipulated into a matrix rotation \mathbf = \mathbf, where \mathbf is the
rotation matrix In linear algebra, a rotation matrix is a transformation matrix that is used to perform a rotation (mathematics), rotation in Euclidean space. For example, using the convention below, the matrix :R = \begin \cos \theta & -\sin \theta \\ \sin \t ...
given by: : \mathbf = \begin 1 - 2s(q_j^2 + q_k^2) & 2s (q_i q_j - q_k q_r) & 2s (q_i q_k + q_j q_r) \\ 2s (q_i q_j + q_k q_r) & 1 - 2s(q_i^2 + q_k^2) & 2s (q_j q_k - q_i q_r) \\ 2s (q_i q_k - q_j q_r) & 2s (q_j q_k + q_i q_r) & 1 - 2s(q_i^2 + q_j^2) \end Here s = \, q\, ^ and if is a unit quaternion, s = 1^ = 1. This can be obtained by using
vector calculus Vector calculus or vector analysis is a branch of mathematics concerned with the differentiation and integration of vector fields, primarily in three-dimensional Euclidean space, \mathbb^3. The term ''vector calculus'' is sometimes used as a ...
and
linear algebra Linear algebra is the branch of mathematics concerning linear equations such as :a_1x_1+\cdots +a_nx_n=b, linear maps such as :(x_1, \ldots, x_n) \mapsto a_1x_1+\cdots +a_nx_n, and their representations in vector spaces and through matrix (mathemat ...
if we express \mathbf p and \mathbf q as scalar and vector parts and use the formula for the multiplication operation in the equation \mathbf = \mathbf \mathbf \mathbf^. If we write \mathbf p as \left(0,\ \mathbf p\right), \mathbf p' as \left(0,\ \mathbf p'\right) and \mathbf q as \left(q_r,\ \mathbf v\right), where \mathbf v = \left(q_i, q_j, q_k\right), our equation turns into \left(0,\ \mathbf p'\right) = \left(q_r,\ \mathbf v\right) \left(0,\ \mathbf p\right) s\left(q_r,\ -\mathbf v\right). By using the formula for multiplication of two quaternions that are expressed as scalar and vector parts, :\left(r_1,\ \vec_1\right) \left(r_2,\ \vec_2\right) = \left(r_1 r_2 - \vec_1 \cdot \vec_2,\ r_1\vec_2 + r_2\vec_1 + \vec_1\times\vec_2\right), this equation can be rewritten as :\begin (0,\ \mathbf p') = &((q_r,\ \mathbf v) (0,\ \mathbf p)) s(q_r,\ -\mathbf v) \\ = &(q_r 0 - \mathbf v \cdot \mathbf p,\ q_r\mathbf p + 0\mathbf v + \mathbf v \times \mathbf p)s(q_r,\ -\mathbf v) \\ = &s(-\mathbf v \cdot \mathbf p,\ q_r\mathbf p + \mathbf v \times \mathbf p)(q_r,\ -\mathbf v) \\ = &s(-\mathbf v \cdot \mathbf p q_r - (q_r\mathbf p + \mathbf v \times \mathbf p)\cdot(-\mathbf v),\ (-\mathbf v \cdot \mathbf p)(-\mathbf v) + q_r(q_r\mathbf p + \mathbf v \times \mathbf p) + (q_r\mathbf p + \mathbf v \times \mathbf p)\times(-\mathbf v)) \\ = &s\left(-\mathbf v \cdot \mathbf p q_r + q_r\mathbf v \cdot \mathbf p,\ \mathbf v\left(\mathbf v \cdot \mathbf p\right) + q_r^2\mathbf p + q_r\mathbf v \times \mathbf p + \mathbf v \times \left(q_r \mathbf p + \mathbf v \times \mathbf p\right)\right) \\ = &\left(0,\ s\left(\mathbf v \otimes \mathbf v + q_r^2\mathbf + 2 q_r mathbf v + mathbf v^2\right) \mathbf p\right), \end where \otimes denotes the
outer product In linear algebra, the outer product of two coordinate vectors is the matrix whose entries are all products of an element in the first vector with an element in the second vector. If the two coordinate vectors have dimensions ''n'' and ''m'', the ...
, \mathbf is the
identity matrix In linear algebra, the identity matrix of size n is the n\times n square matrix with ones on the main diagonal and zeros elsewhere. It has unique properties, for example when the identity matrix represents a geometric transformation, the obje ...
and mathbf v is the transformation matrix that when multiplied from the right with a vector \mathbf u gives the
cross product In mathematics, the cross product or vector product (occasionally directed area product, to emphasize its geometric significance) is a binary operation on two vectors in a three-dimensional oriented Euclidean vector space (named here E), and ...
\mathbf v \times \mathbf u. Since \mathbf p' = \mathbf\mathbf p, we can identify \mathbf as s\left(\mathbf v \otimes \mathbf v + q_r^2\mathbf + 2 q_r mathbf v + mathbf v^2\right), which upon expansion should result in the expression written in matrix form above.


Recovering the axis-angle representation

The expression \mathbf \mathbf \mathbf^ rotates any vector quaternion \mathbf around an axis given by the vector \mathbf by the angle \theta, where \mathbf and \theta depends on the quaternion \mathbf = q_r + q_i \mathbf + q_j \mathbf + q_k \mathbf. \mathbf and \theta can be found from the following equations: :\begin (a_x, a_y, a_z) = &\frac \\ pt \theta = 2 \operatorname &\left(\sqrt,\, q_r \right), \end where \operatorname is the two-argument arctangent. While \theta = 2 \operatorname (q_r) works, it is numerically unstable (inaccurate) near q_r = \pm1 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 \varphi around this axis. The associated quaternion is given by S = \cos\frac + \mathbf\sin\frac. Then the composition of the rotation with is the rotation with rotation axis and angle defined by the product of the quaternions A = \cos\frac + \mathbf\sin\frac \quad \text \quad B = \cos\frac + \mathbf\sin\frac, that is C = \cos\frac + \mathbf\sin\frac = \left(\cos\frac + \mathbf \sin\frac\right) \left(\cos\frac + \mathbf\sin\frac\right). Expand this product to obtain \cos\frac + \mathbf\sin\frac = \left( \cos\frac \cos\frac - \mathbf \cdot \mathbf \sin\frac \sin\frac\right) + \left(\mathbf \sin\frac \cos\frac + \mathbf \sin\frac \cos\frac + \mathbf \times \mathbf \sin\frac \sin\frac \right). Divide both sides of this equation by the identity, which is the law of cosines on a sphere, \cos\frac = \cos\frac \cos\frac - \mathbf \cdot \mathbf \sin\frac \sin\frac, and compute \mathbf \tan\frac = \frac. This is Rodrigues' 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). 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. Hamilton
William Rowan Hamilton Sir William Rowan Hamilton (4 August 1805 – 2 September 1865) was an Irish astronomer, mathematician, and physicist who made numerous major contributions to abstract algebra, classical mechanics, and optics. His theoretical works and mathema ...
(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 Trinity College Dublin (), officially titled The College of the Holy and Undivided Trinity of Queen Elizabeth near Dublin, and legally incorporated as Trinity College, the University of Dublin (TCD), is the sole constituent college of the Univ ...
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 Elliptic geometry is an example of a geometry in which Euclid's parallel postulate does not hold. Instead, as in spherical geometry, there are no parallel lines since any two lines must intersect. However, unlike in spherical geometry, two lines ...
.


Axis–angle composition

The normalized rotation axis, removing the \cos\frac from the expanded product, leaves the vector which is the rotation axis, times some constant. Care should be taken normalizing the axis vector when \gamma is 0 or k 2\pi where the vector is near 0; which is identity, or 0 rotation around any axis. \begin \gamma &= 2\cos^\left(\cos\frac \cos\frac - \mathbf \cdot \mathbf \sin\frac \sin\frac\right) \\ \mathbf &= \mathbf \sin\frac \cos\frac + \mathbf \sin\frac \cos\frac + \mathbf \times \mathbf \sin\frac \sin\frac \end Or with angle addition trigonometric substitutions... \begin \gamma &= 2 \cos^ \left(\left(1 - \mathbf \cdot \mathbf\right) \cos\frac + \left(1 + \mathbf\cdot \mathbf\right) \cos\frac\right) \\ \mathbf &= \left(\sin\frac + \sin\frac\right) \mathbf + \left(\sin\frac - \sin\frac\right) \mathbf + \left(\cos\frac - \cos\frac\right) \mathbf \times \mathbf \end finally normalizing the rotation axis: \frac or \frac.


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 In mathematics, matrix calculus is a specialized notation for doing multivariable calculus, especially over spaces of matrix (mathematics), matrices. It collects the various partial derivatives of a single Function (mathematics), function with ...
notation as :\begin \frac \equiv \left frac,\frac,\frac,\frac \right= \left \mathbf-(\mathbf)^*,(\mathbf)^*-\mathbf,(\mathbf)^*-\mathbf,(\mathbf)^*-\mathbf \right \end A derivation can be found in.


Background


Quaternions

The
complex numbers In mathematics, a complex number is an element of a number system that extends the real numbers with a specific element denoted , called the imaginary unit and satisfying the equation i^= -1; every complex number can be expressed in the form a ...
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: : (a+b\mathbf)(c+d\mathbf) = ac + ad\mathbf + b\mathbfc + b\mathbfd\mathbf = ac + ad\mathbf + bc\mathbf + bd\mathbf^2 = (ac - bd) + (bc + ad) \mathbf. In the same way the quaternions can be defined by introducing abstract symbols , , which satisfy the rules and the usual algebraic rules ''except'' the
commutative law In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. Perhaps most familiar as a p ...
of multiplication (a familiar example of such a noncommutative multiplication is
matrix multiplication In mathematics, specifically in linear algebra, matrix multiplication is a binary operation that produces a matrix (mathematics), matrix from two matrices. For matrix multiplication, the number of columns in the first matrix must be equal to the n ...
). From this all of the rules of quaternion arithmetic follow, such as the rules on multiplication of quaternion basis elements. Using these rules, one can show that: : \begin &(a + b\mathbf + c\mathbf + d\mathbf) (e + f\mathbf + g\mathbf + h\mathbf) = \\ &(ae - bf - cg - dh) + (af + be + ch - dg) \mathbf + (ag - bh + ce + df) \mathbf + (ah + bg - cf + de) \mathbf. \end The imaginary part b\mathbf + c\mathbf + d\mathbf of a quaternion behaves like a vector \vec = (b,c,d) in three-dimensional
vector space In mathematics and physics, a vector space (also called a linear space) is a set (mathematics), set whose elements, often called vector (mathematics and physics), ''vectors'', can be added together and multiplied ("scaled") by numbers called sc ...
, and the real part behaves like a scalar in . When quaternions are used in geometry, it is more convenient to define them as a scalar plus a vector: : a + b\mathbf + c\mathbf + d\mathbf = a + \vec. Some might find it strange to add a ''number'' to a ''vector'', as they are objects of very different natures, or to ''multiply'' two vectors together, as this operation is usually undefined. However, if one remembers that it is a mere notation for the real and imaginary parts of a quaternion, it becomes more legitimate. In other words, the correct reasoning is the addition of two quaternions, one with zero vector/imaginary part, and another one with zero scalar/real part: :q_1 = s + \vec = \left(s, \vec\right) + \left(0, \vec\right). We can express quaternion multiplication in the modern language of vector
cross A cross is a religious symbol consisting of two Intersection (set theory), intersecting Line (geometry), lines, usually perpendicular to each other. The lines usually run vertically and horizontally. A cross of oblique lines, in the shape of t ...
and
dot product In mathematics, the dot product or scalar productThe term ''scalar product'' means literally "product with a Scalar (mathematics), scalar as a result". It is also used for other symmetric bilinear forms, for example in a pseudo-Euclidean space. N ...
s (which were actually inspired by the quaternions in the first place). When multiplying the vector/imaginary parts, in place of the rules we have the quaternion multiplication rule: : \vec \vec = - \vec \cdot \vec + \vec \times \vec, where: * \vec \vec is the resulting quaternion, * \vec \times \vec is vector cross product (a vector), * \vec \cdot \vec is vector scalar product (a scalar). Quaternion multiplication is noncommutative (because of the cross product, which anti-commutes), while scalar–scalar and scalar–vector multiplications commute. From these rules it follows immediately that (see ): :q_1 q_2 = \left(s + \vec\right) \left(t + \vec\right) = \left(s t - \vec \cdot \vec\right) + \left(s \vec + t \vec + \vec \times \vec\right). The (left and right) multiplicative inverse or reciprocal of a nonzero quaternion is given by the conjugate-to-norm ratio ( see details): :q_1^ = \left(s + \vec\right)^ = \frac = \frac, as can be verified by direct calculation (note the similarity to the multiplicative inverse of complex numbers).


Rotation identity

Let \vec be a unit vector (the rotation axis) and let q = \cos \frac + \vec \sin \frac. Our goal is to show that :\vec' = q \vec q^ = \left( \cos \frac + \vec \sin \frac \right) \, \vec \, \left( \cos \frac - \vec \sin \frac \right) yields the vector \vec rotated by an angle \alpha around the axis \vec. Expanding out (and bearing in mind that \vec\vec = \vec \times \vec - \vec \cdot \vec), we have :\begin \vec' &= \vec \cos^2 \frac + \left(\vec\vec - \vec\vec\right) \sin \frac \cos \frac - \vec\vec\vec \sin^2 \frac \\ pt&= \vec \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac - \left(\left(\vec \times \vec\right) - \left(\vec \cdot \vec\right)\right)\vec \sin^2 \frac \\ pt&= \vec \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac - \left(\left(\vec \times \vec\right)\vec - \left(\vec \cdot \vec\right)\vec\right) \sin^2 \frac \\ pt&= \vec \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac - \left(\left(\left(\vec \times \vec\right) \times \vec - \left(\vec \times \vec\right) \cdot \vec\right) - \left(\vec \cdot \vec\right)\vec\right) \sin^2 \frac \\ pt&= \vec \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac - \left(\left(\vec - \left(\vec \cdot \vec\right)\vec\right) - 0 - \left(\vec \cdot \vec\right)\vec\right) \sin^2 \frac \\ pt&= \vec \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac - \left(\vec - 2 \vec \left(\vec \cdot \vec\right)\right) \sin^2 \frac \\ pt&= \vec \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac + \left(2 \vec \left(\vec \cdot \vec\right) - \vec\right) \sin^2 \frac \\ pt\end If we let \vec_ and \vec_ equal the components of \vec perpendicular and parallel to \vec respectively, then \vec = \vec_ + \vec_ and \vec \left(\vec \cdot \vec\right) = \vec_, leading to :\begin \vec' &= \vec \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac + \left(2 \vec \left(\vec \cdot \vec\right) - \vec\right) \sin^2 \frac \\ pt&= \left(\vec_ + \vec_\right) \cos^2 \frac + 2 \left(\vec \times \vec\right) \sin \frac \cos \frac + \left(\vec_ - \vec_\right) \sin^2 \frac \\ pt&= \vec_ \left(\cos^2 \frac + \sin^2 \frac\right) + \left(\vec \times \vec\right) \left(2 \sin \frac \cos \frac\right) + \vec_ \left(\cos^2 \frac - \sin^2 \frac\right) \\ pt\end Using the trigonometric pythagorean and double-angle identities, we then have :\begin \vec' &= \vec_ \left(\cos^2 \frac + \sin^2 \frac\right) + \left(\vec \times \vec\right) \left(2 \sin \frac \cos \frac\right) + \vec_ \left(\cos^2 \frac - \sin^2 \frac\right) \\ pt&= \vec_ + \left(\vec \times \vec\right) \sin \alpha + \vec_\bot \cos \alpha \end This is the formula of a rotation by \alpha around the axis.


Quaternion rotation operations

A very formal explanation of the properties used in this section is given by Altman.


The hypersphere of rotations


Visualizing the space of rotations

Unit quaternions represent the group of Euclidean rotations in three dimensions in a very straightforward way. The correspondence between rotations and quaternions can be understood by first visualizing the space of rotations itself. In order to visualize the space of rotations, it helps to consider a simpler case. Any rotation in three dimensions can be described by a rotation by some
angle In Euclidean geometry, an angle can refer to a number of concepts relating to the intersection of two straight Line (geometry), lines at a Point (geometry), point. Formally, an angle is a figure lying in a Euclidean plane, plane formed by two R ...
about some
axis An axis (: axes) may refer to: Mathematics *A specific line (often a directed line) that plays an important role in some contexts. In particular: ** Coordinate axis of a coordinate system *** ''x''-axis, ''y''-axis, ''z''-axis, common names ...
; for our purposes, we will use an axis ''vector'' to establish
handedness In human biology, handedness is an individual's preferential use of one hand, known as the dominant hand, due to and causing it to be stronger, faster or more Fine motor skill, dextrous. The other hand, comparatively often the weaker, less dext ...
for our angle. Consider the special case in which the axis of rotation lies in the ''xy'' plane. We can then specify the axis of one of these rotations by a point on a circle through which the vector crosses, and we can select the radius of the circle to denote the angle of rotation. Similarly, a rotation whose axis of rotation lies in the ''xy'' plane can be described as a point on a sphere of ''fixed'' radius in ''three'' dimensions. Beginning at the north pole of a sphere in three-dimensional space, we specify the point at the north pole to be the identity rotation (a zero angle rotation). Just as in the case of the identity rotation, no axis of rotation is defined, and the angle of rotation (zero) is irrelevant. A rotation having a very small rotation angle can be specified by a slice through the sphere parallel to the ''xy'' plane and very near the north pole. The circle defined by this slice will be very small, corresponding to the small angle of the rotation. As the rotation angles become larger, the slice moves in the negative direction, and the circles become larger until the equator of the sphere is reached, which will correspond to a rotation angle of 180 degrees. Continuing southward, the radii of the circles now become smaller (corresponding to the absolute value of the angle of the rotation considered as a negative number). Finally, as the south pole is reached, the circles shrink once more to the identity rotation, which is also specified as the point at the south pole. Notice that a number of characteristics of such rotations and their representations can be seen by this visualization. The space of rotations is continuous, each rotation has a neighborhood of rotations which are nearly the same, and this neighborhood becomes flat as the neighborhood shrinks. Also, each rotation is actually represented by two antipodal points on the sphere, which are at opposite ends of a line through the center of the sphere. This reflects the fact that each rotation can be represented as a rotation about some axis, or, equivalently, as a negative rotation about an axis pointing in the opposite direction (a so-called double cover). The "latitude" of a circle representing a particular rotation angle will be half of the angle represented by that rotation, since as the point is moved from the north to south pole, the latitude ranges from zero to 180 degrees, while the angle of rotation ranges from 0 to 360 degrees. (the "longitude" of a point then represents a particular axis of rotation.) Note however that this set of rotations is not closed under composition. Two successive rotations with axes in the ''xy'' plane will not necessarily give a rotation whose axis lies in the ''xy'' plane, and thus cannot be represented as a point on the sphere. This will not be the case with a general rotation in 3-space, in which rotations do form a closed set under composition. This visualization can be extended to a general rotation in 3-dimensional space. The identity rotation is a point, and a small angle of rotation about some axis can be represented as a point on a sphere with a small radius. As the angle of rotation grows, the sphere grows, until the angle of rotation reaches 180 degrees, at which point the sphere begins to shrink, becoming a point as the angle approaches 360 degrees (or zero degrees from the negative direction). This set of expanding and contracting spheres represents a hypersphere in four dimensional space (a 3-sphere). Just as in the simpler example above, each rotation represented as a point on the hypersphere is matched by its antipodal point on that hypersphere. The "latitude" on the hypersphere will be half of the corresponding angle of rotation, and the neighborhood of any point will become "flatter" (i.e. be represented by a 3-D Euclidean space of points) as the neighborhood shrinks. This behavior is matched by the set of unit quaternions: A general quaternion represents a point in a four dimensional space, but constraining it to have unit magnitude yields a three-dimensional space equivalent to the surface of a hypersphere. The magnitude of the unit quaternion will be unity, corresponding to a hypersphere of unit radius. The vector part of a unit quaternion represents the radius of the 2-sphere corresponding to the axis of rotation, and its magnitude is the sine of half the angle of rotation. Each rotation is represented by two unit quaternions of opposite sign, and, as in the space of rotations in three dimensions, the quaternion product of two unit quaternions will yield a unit quaternion. Also, the space of unit quaternions is "flat" in any infinitesimal neighborhood of a given unit quaternion.


Parameterizing the space of rotations

We can parameterize the surface of a sphere with two coordinates, such as latitude and longitude. But latitude and longitude are ill-behaved ( degenerate as described by the
hairy ball theorem The hairy ball theorem of algebraic topology (sometimes called the hedgehog theorem in Europe) states that there is no nonvanishing continuous function, continuous tangent vector field on even-dimensional n‑sphere, ''n''-spheres. For the ord ...
) at the north and south poles, though the poles are not intrinsically different from any other points on the sphere. At the poles (latitudes +90° and −90°), the longitude becomes meaningless. It can be shown that no two-parameter coordinate system can avoid such degeneracy. We can avoid such problems by embedding the sphere in three-dimensional space and parameterizing it with three Cartesian coordinates , placing the north pole at , the south pole at , and the equator at , . Points on the sphere satisfy the constraint , so we still have just two
degrees of freedom In many scientific fields, the degrees of freedom of a system is the number of parameters of the system that may vary independently. For example, a point in the plane has two degrees of freedom for translation: its two coordinates; a non-infinite ...
though there are three coordinates. A point on the sphere represents a rotation in the ordinary space around the horizontal axis directed by the vector by an angle \alpha= 2 \cos^ w = 2 \sin^ \sqrt. In the same way the hyperspherical space of 3D rotations can be parameterized by three angles (
Euler angles The Euler angles are three angles introduced by Leonhard Euler to describe the Orientation (geometry), orientation of a rigid body with respect to a fixed coordinate system.Novi Commentarii academiae scientiarum Petropolitanae 20, 1776, pp. 189� ...
), but any such parameterization is degenerate at some points on the hypersphere, leading to the problem of
gimbal lock Gimbal lock is the loss of one degree of freedom (mechanics), degree of freedom in a multi-dimensional mechanism at certain alignments of the axes. In a three-dimensional three-gimbal mechanism, gimbal lock occurs when the axes of two of the gi ...
. We can avoid this by using four Euclidean coordinates , with . The point represents a rotation around the axis directed by the vector by an angle \alpha = 2 \cos^ w = 2 \sin^ \sqrt.


Explaining quaternions' properties with rotations


Non-commutativity

The multiplication of quaternions is non-commutative. This fact explains how the formula can work at all, having by definition. Since the multiplication of unit quaternions corresponds to the composition of three-dimensional rotations, this property can be made intuitive by showing that three-dimensional rotations are not commutative in general. The figure to the right illustrates this with dice. Use the right hand to create a pair of 90 degree rotations. Both dice are initially configured as shown in the upper left-hand corner (with 1 dot on the top face.) Path A begins with a rotation about the axis (using the
right-hand rule In mathematics and physics, the right-hand rule is a Convention (norm), convention and a mnemonic, utilized to define the orientation (vector space), orientation of Cartesian coordinate system, axes in three-dimensional space and to determine the ...
.), followed by a rotation about the axis, resulting in the configuration shown in the lower left corner (5 dots on the top face.) Path B reverses the order of operations, resulting with 3 dots on top. Alternatively, set two books next to each other. Rotate one of them 90 degrees clockwise around the axis, then flip it 180 degrees around the axis. Take the other book, flip it 180° around axis first, and 90° clockwise around later. The two books do not end up parallel. This shows that, in general, the composition of two different rotations around two distinct spatial axes will not commute.


Orientation

The
vector cross product In mathematics, the cross product or vector product (occasionally directed area product, to emphasize its geometric significance) is a binary operation on two vectors in a three-dimensional oriented Euclidean vector space (named here E), and ...
, used to define the axis–angle representation, does confer an orientation ("handedness") to space: in a three-dimensional vector space, the three vectors in the equation will always form a right-handed set (or a left-handed set, depending on how the cross product is defined), thus fixing an orientation in the vector space. Alternatively, the dependence on orientation is expressed in referring to such \vec that specifies a rotation as to ''
axial vector Axial may refer to: * one of the Anatomical terms of location#Other directional terms, anatomical directions describing relationships in an animal body * In geometry: :* a geometric term of location :* an axis of rotation * In chemistry, referring ...
s''. In quaternionic formalism the choice of an orientation of the space corresponds to order of multiplication: but . If one reverses the orientation, then the formula above becomes , i.e., a unit is replaced with the conjugate quaternion – the same behaviour as of axial vectors.


Alternative conventions

It is reported that the existence and continued usage of an alternative quaternion convention in the aerospace and, to a lesser extent, robotics community is incurring a ''significant and ongoing cost''. This alternative convention is proposed by Shuster M.D. in and departs from tradition by reversing the definition for multiplying quaternion basis elements such that under Shuster's convention, \mathbf \mathbf = -\mathbf whereas Hamilton's definition is \mathbf\mathbf = \mathbf. This convention is also referred to as "JPL convention" for its use in some parts of NASA's
Jet Propulsion Laboratory The Jet Propulsion Laboratory (JPL) is a Federally funded research and development centers, federally funded research and development center (FFRDC) in La Cañada Flintridge, California, Crescenta Valley, United States. Founded in 1936 by Cali ...
. Under Shuster's convention, the formula for multiplying two quaternions is altered such that :\left(r_1,\ \vec_1\right) \left(r_2,\ \vec_2\right) = \left(r_1 r_2 - \vec_1\cdot\vec_2,\ r_1\vec_2 + r_2\vec_1 \mathbin \vec_1\times\vec_2\right), \qquad \text The formula for rotating a vector by a quaternion is altered to be :\begin \mathbf p'_\text = &(\mathbf v \otimes \mathbf v + q_r^2\mathbf \mathbin 2 q_r mathbf v + mathbf v^2) \mathbf p & \text \\ = &\ (\mathbf \mathbin 2 q_r mathbf v + 2 mathbf v^2) \mathbf p & \end To identify the changes under Shuster's convention, see that the sign before the cross product is flipped from plus to minus. Finally, the formula for converting a quaternion to a rotation matrix is altered to be :\begin \mathbf_ &= \mathbf \mathbin 2 q_r mathbf v + 2 mathbf v^2 \qquad \text \\ &= \begin 1 - 2s (q_j^2 + q_k^2) & 2 (q_i q_j + q_k q_r) & 2 (q_i q_k - q_j q_r) \\ 2 (q_i q_j - q_k q_r) & 1 - 2s (q_i^2 + q_k^2) & 2 (q_j q_k + q_i q_r) \\ 2 (q_i q_k + q_j q_r) & 2 (q_j q_k - q_i q_r) & 1 - 2s (q_i^2 + q_j^2) \end \end which is exactly the
transpose In linear algebra, the transpose of a Matrix (mathematics), matrix is an operator which flips a matrix over its diagonal; that is, it switches the row and column indices of the matrix by producing another matrix, often denoted by (among other ...
of the rotation matrix converted under the traditional convention.


Software applications by convention used

The table below groups applications by their adherence to either quaternion convention: While use of either convention does not impact the capability or correctness of applications thus created, the authors of argued that the Shuster convention should be abandoned because it departs from the much older quaternion multiplication convention by Hamilton and may never be adopted by the mathematical or theoretical physics areas.


Comparison with other representations of rotations


Advantages of quaternions

The representation of a rotation as a quaternion (4 numbers) is more compact than the representation as an
orthogonal matrix In linear algebra, an orthogonal matrix, or orthonormal matrix, is a real square matrix whose columns and rows are orthonormal vectors. One way to express this is Q^\mathrm Q = Q Q^\mathrm = I, where is the transpose of and is the identi ...
(9 numbers). Furthermore, for a given axis and angle, one can easily construct the corresponding quaternion, and conversely, for a given quaternion one can easily read off the axis and the angle. Both of these are much harder with matrices or
Euler angles The Euler angles are three angles introduced by Leonhard Euler to describe the Orientation (geometry), orientation of a rigid body with respect to a fixed coordinate system.Novi Commentarii academiae scientiarum Petropolitanae 20, 1776, pp. 189� ...
. In
video game A video game or computer game is an electronic game that involves interaction with a user interface or input device (such as a joystick, game controller, controller, computer keyboard, keyboard, or motion sensing device) to generate visual fe ...
s and other applications, one is often interested in "smooth rotations", meaning that the scene should slowly rotate and not in a single step. This can be accomplished by choosing a
curve In mathematics, a curve (also called a curved line in older texts) is an object similar to a line, but that does not have to be straight. Intuitively, a curve may be thought of as the trace left by a moving point. This is the definition that ...
such as the spherical linear interpolation in the quaternions, with one endpoint being the identity transformation 1 (or some other initial rotation) and the other being the intended final rotation. This is more problematic with other representations of rotations. When composing several rotations on a computer, rounding errors necessarily accumulate. A quaternion that is slightly off still represents a rotation after being normalized: a matrix that is slightly off may not be
orthogonal In mathematics, orthogonality (mathematics), orthogonality is the generalization of the geometric notion of ''perpendicularity''. Although many authors use the two terms ''perpendicular'' and ''orthogonal'' interchangeably, the term ''perpendic ...
any more and is harder to convert back to a proper orthogonal matrix. Quaternions also avoid a phenomenon called
gimbal lock Gimbal lock is the loss of one degree of freedom (mechanics), degree of freedom in a multi-dimensional mechanism at certain alignments of the axes. In a three-dimensional three-gimbal mechanism, gimbal lock occurs when the axes of two of the gi ...
which can result when, for example in pitch/yaw/roll rotational systems, the pitch is rotated 90° up or down, so that yaw and roll then correspond to the same motion, and a degree of freedom of rotation is lost. In a
gimbal A gimbal is a pivoted support that permits rotation of an object about an axis. A set of three gimbals, one mounted on the other with orthogonal pivot axes, may be used to allow an object mounted on the innermost gimbal to remain independent of ...
-based aerospace
inertial navigation system An inertial navigation system (INS; also inertial guidance system, inertial instrument) is a navigation device that uses motion sensors (accelerometers), rotation sensors (gyroscopes) and a computer to continuously calculate by dead reckoning th ...
, for instance, this could have disastrous results if the aircraft is in a steep dive or ascent.


Conversion to and from the matrix representation


From a quaternion to an orthogonal matrix

The
orthogonal matrix In linear algebra, an orthogonal matrix, or orthonormal matrix, is a real square matrix whose columns and rows are orthonormal vectors. One way to express this is Q^\mathrm Q = Q Q^\mathrm = I, where is the transpose of and is the identi ...
corresponding to a rotation by the unit quaternion (with ) when post-multiplying with a column vector is given by :R = \begin a^2 + b^2 - c^2 - d^2 & 2bc - 2ad & 2bd + 2ac \\ 2bc + 2ad & a^2 - b^2 + c^2 - d^2 & 2cd - 2ab \\ 2bd - 2ac & 2cd+2ab & a^2 -b^2 -c^2 + d^2 \\ \end. This rotation matrix is used on vector as w_\text = R \cdot w. The quaternion representation of this rotation is given by: :\begin 0\\ w_\text \end = z \begin 0 \\ w\end z^*, where z^* is the conjugate of the quaternion z , given by \mathbf^* = a - b\mathbf - c\mathbf - d\mathbf Also, quaternion multiplication is defined as (assuming and are quaternions, like above): ab = \left(a_0 b_0 - \vec \cdot \vec; a_0 \vec + b_0 \vec + \vec \times \vec\right) where the order , is important since the cross product of two vectors is not commutative. A more efficient calculation in which the quaternion does not need to be unit normalized is given by :R = \begin 1 - cc - dd & bc - ad & bd + ac \\ bc + ad & 1 - bb - dd & cd - ab \\ bd - ac & cd + ab & 1 - bb - cc \\ \end, where the following intermediate quantities have been defined: :\begin & \ \ s = 2/(a \cdot a + b \cdot b + c \cdot c + d \cdot d), \\ & \begin bs = b \cdot s, & cs = c \cdot s, & ds = d \cdot s, \\ ab = a \cdot bs, & ac = a \cdot cs, & ad = a \cdot ds, \\ bb = b \cdot bs, & bc = b \cdot cs, & bd = b \cdot ds, \\ cc = c \cdot cs, & cd = c \cdot ds, & dd = d \cdot ds . \\ \end \end


From an orthogonal matrix to a quaternion

One must be careful when converting a rotation matrix to a quaternion, as several straightforward methods tend to be unstable when the trace (sum of the diagonal elements) of the rotation matrix is zero or very small. For a stable method of converting an orthogonal matrix to a quaternion, see the Rotation matrix#Quaternion.


Fitting quaternions

The above section described how to recover a quaternion from a
rotation matrix In linear algebra, a rotation matrix is a transformation matrix that is used to perform a rotation (mathematics), rotation in Euclidean space. For example, using the convention below, the matrix :R = \begin \cos \theta & -\sin \theta \\ \sin \t ...
. Suppose, however, that we have some matrix that is not a pure rotation—due to
round-off error In computing, a roundoff error, also called rounding error, is the difference between the result produced by a given algorithm using exact arithmetic and the result produced by the same algorithm using finite-precision, rounded arithmetic. Roun ...
s, for example—and we wish to find the quaternion that most accurately represents . In that case we construct a symmetric matrix : K = \frac \begin Q_-Q_-Q_ & Q_+Q_ & Q_+Q_ & Q_-Q_ \\ Q_+Q_ & Q_-Q_-Q_ & Q_+Q_ & Q_-Q_ \\ Q_+Q_ & Q_+Q_ & Q_-Q_-Q_ & Q_-Q_ \\ Q_-Q_ & Q_-Q_ & Q_-Q_ & Q_+Q_+Q_ \end , and find the
eigenvector In linear algebra, an eigenvector ( ) or characteristic vector is a vector that has its direction unchanged (or reversed) by a given linear transformation. More precisely, an eigenvector \mathbf v of a linear transformation T is scaled by ...
corresponding to the largest eigenvalue (that value will be 1 if and only if is a pure rotation). The quaternion so obtained will correspond to the rotation closest to the original matrix .


Performance comparisons

This section discusses the performance implications of using quaternions versus other methods (axis/angle or rotation matrices) to perform rotations in 3D.


Results

Only three of the quaternion components are independent, as a rotation is represented by a unit quaternion. For further calculation one usually needs all four elements, so all calculations would suffer additional expense from recovering the fourth component. Likewise, angle–axis can be stored in a three-component vector by multiplying the unit direction by the angle (or a function thereof), but this comes at additional computational cost when using it for calculations. Similarly, a rotation matrix requires orthogonal basis vectors, so in 3D space the third vector can unambiguously be calculated from the first two vectors with a cross product (though there is ambiguity in the sign of the third vector if improper rotations are allowed). * Quaternions can be implicitly converted to a rotation-like matrix (12 multiplications and 12 additions/subtractions), which levels the following vectors rotating cost with the rotation matrix method.


Used methods

There are three basic approaches to rotating a vector : # Compute the matrix product of a
rotation matrix In linear algebra, a rotation matrix is a transformation matrix that is used to perform a rotation (mathematics), rotation in Euclidean space. For example, using the convention below, the matrix :R = \begin \cos \theta & -\sin \theta \\ \sin \t ...
and the original
column A column or pillar in architecture and structural engineering is a structural element that transmits, through compression, the weight of the structure above to other structural elements below. In other words, a column is a compression member ...
matrix representing . This requires 3 × (3 multiplications + 2 additions) = 9 multiplications and 6 additions, the most efficient method for rotating a vector. # A rotation can be represented by a unit-length quaternion with scalar (real) part and vector (imaginary) part . The rotation can be applied to a 3D vector via the formula \vec_\text=\vec + 2\vec \times (\vec \times \vec + w \vec). This requires only 15 multiplications and 15 additions to evaluate (or 18 multiplications and 12 additions if the factor of 2 is done via multiplication.) This formula, originally thought to be used with axis/angle notation (Rodrigues' formula), can also be applied to quaternion notation. This yields the same result as the less efficient but more compact formula of quaternion multiplication \vec_\text = q \vec q^. # Use the angle/axis formula to convert an angle/axis to a
rotation matrix In linear algebra, a rotation matrix is a transformation matrix that is used to perform a rotation (mathematics), rotation in Euclidean space. For example, using the convention below, the matrix :R = \begin \cos \theta & -\sin \theta \\ \sin \t ...
then multiplying with a vector, or, similarly, use a formula to convert quaternion notation to a rotation matrix, then multiplying with a vector. Converting the angle/axis to costs 12 multiplications, 2 function calls (sin, cos), and 10 additions/subtractions; from item 1, rotating using adds an additional 9 multiplications and 6 additions for a total of 21 multiplications, 16 add/subtractions, and 2 function calls (sin, cos). Converting a quaternion to costs 12 multiplications and 12 additions/subtractions; from item 1, rotating using adds an additional 9 multiplications and 6 additions for a total of 21 multiplications and 18 additions/subtractions.


Pairs of unit quaternions as rotations in 4D space

A pair of unit quaternions \mathbf_ = a_ + b_i + c_j + d_k and \mathbf_ = a_ + b_i + c_j + d_k can represent any rotation in 4D space. Given a four-dimensional vector \vec, expressed as a quaternion \vec = w + xi + yj + zk, we can rotate it as follows: :f\left(\vec\right) = \mathbf_ \vec \mathbf_ = M_M_ \vec = \begin a_&-b_&-c_&-d_\\ b_& a_&-d_& c_\\ c_& d_& a_&-b_\\ d_&-c_& b_& a_ \end \begin a_&-b_&-c_&-d_\\ b_& a_& d_&-c_\\ c_&-d_& a_& b_\\ d_& c_&-b_& a_ \end \beginw\\x\\y\\z\end, where the matrices M_ and M_ represent left and right quaternion multiplications, respectively. Together, these matrices form an isoclinic decomposition of a rotation in \mathbb^4. Since quaternion multiplication is
associative In mathematics, the associative property is a property of some binary operations that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement for express ...
, we have: :(\mathbf_ \vec) \mathbf_ = M_M_\vec = M_M_\vec = \mathbf_ (\vec \mathbf_). Thus, the two matrices M_ and M_ must commute. This implies the existence of two commuting
subgroup In group theory, a branch of mathematics, a subset of a group G is a subgroup of G if the members of that subset form a group with respect to the group operation in G. Formally, given a group (mathematics), group under a binary operation  ...
s within the group of four-dimensional rotations. An arbitrary four-dimensional rotation has six degrees of freedom, with each matrix contributing three of these six degrees of freedom. Since the generators of the four-dimensional rotations can be represented by pairs of quaternions (as follows), all four-dimensional rotations can also be represented. :\begin \mathbf_ \vec \mathbf_ &= \begin 1 &-dt_&-dt_&-dt_\\ dt_&1 &-dt_&-dt_\\ dt_& dt_&1 &-dt_\\ dt_& dt_& dt_&1 \end \begin w\\ x\\ y\\ z \end \\ pt \mathbf_ &= 1+i+j+k \\ pt \mathbf_ &= 1+i+j+k \end


See also

* Anti-twister mechanism * Binary polyhedral group *
Biquaternion In abstract algebra, the biquaternions are the numbers , where , and are complex numbers, or variants thereof, and the elements of multiply as in the quaternion group and commute with their coefficients. There are three types of biquaternions cor ...
* Charts on SO(3) *
Clifford algebra In mathematics, a Clifford algebra is an algebra generated by a vector space with a quadratic form, and is a unital associative algebra with the additional structure of a distinguished subspace. As -algebras, they generalize the real number ...
s * Conversion between quaternions and Euler angles *
Covering space In topology, a covering or covering projection is a continuous function, map between topological spaces that, intuitively, Local property, locally acts like a Projection (mathematics), projection of multiple copies of a space onto itself. In par ...
* Dual quaternion * Applications of dual quaternions to 2D geometry *
Elliptic geometry Elliptic geometry is an example of a geometry in which Euclid's parallel postulate does not hold. Instead, as in spherical geometry, there are no parallel lines since any two lines must intersect. However, unlike in spherical geometry, two lines ...
* Rotation formalisms in three dimensions *
Rotation (mathematics) Rotation in mathematics is a concept originating in geometry. Any rotation is a motion of a certain space that preserves at least one point. It can describe, for example, the motion of a rigid body around a fixed point. Rotation can have a s ...
* Spin group * Slerp, spherical linear interpolation * Olinde Rodrigues *
William Rowan Hamilton Sir William Rowan Hamilton (4 August 1805 – 2 September 1865) was an Irish astronomer, mathematician, and physicist who made numerous major contributions to abstract algebra, classical mechanics, and optics. His theoretical works and mathema ...


References


Further reading

* * *


External links and resources

* * on
Rosetta Code Rosetta Code is a wiki-based programming chrestomathy website with implementations of common algorithms and solutions to various computer programming, programming problems in many different programming languages. It is named for the Rosetta Stone ...
* * * * * * * *{{cite web, url=https://eater.net/quaternions , title= Visual representation of quaternion rotation Quaternions Rotation in three dimensions Rigid bodies mechanics 3D computer graphics