# Rotation formalisms in three dimensions

{{ safesubst:#invoke:Unsubst||$N=Merge from |date=__DATE__ |$B= Template:MboxTemplate:DMCTemplate:Merge partner }} In geometry, various formalisms exist to express a rotation in three dimensions as a mathematical transformation. In physics, this concept is applied to classical mechanics where rotational (or angular) kinematics is the science of quantitative description of a purely rotational motion. The orientation of an object at a given instant is described with the same tools, as it is defined as an imaginary rotation from a reference placement in space, rather than an actually observed rotation from a previous placement in space.

According to Euler's rotation theorem the rotation of a rigid body (or three-dimensional coordinate system with the fixed origin) is described by a single rotation about some axis. Such a rotation may be uniquely described by a minimum of three real parameters. However, for various reasons, there are several ways to represent it. Many of these representations use more than the necessary minimum of three parameters, although each of them still has only three degrees of freedom.

An example where rotation representation is used is in computer vision, where an automated observer needs to track a target. Let's consider a rigid body, with three orthogonal unit vectors fixed to its body (representing the three axes of the object's local coordinate system). The basic problem is to specify the orientation of these three unit vectors, and hence the rigid body, with respect to the observer's coordinate system, regarded as a reference placement in space.

## Rotations and motions

{{#invoke:main|main}} Rotation formalisms are focused on proper (orientation-preserving) motions of the Euclidean space with one fixed point, that a rotation refers to. Although physical motions with a fixed point are an important case (such as ones described in the center-of-mass frame, or motions of a joint), this approach creates a knowledge about all motions. Any proper motion of the Euclidean space decomposes to a rotation around the origin and a translation. Whichever the order of their composition will be, the "pure" rotation component wouldn't change, uniquely determined by the complete motion.

One can also understand "pure" rotations as linear maps in a vector space equipped with Euclidean structure, not as maps of points of a corresponding affine space. In other words, a rotation formalism captures only the rotational part of a motion, that contains three degrees of freedom, and ignores the translational part, that contains another three.

## Formalism alternatives

### Rotation matrix

{{#invoke:main|main}}

The above mentioned triad of unit vectors is also called a basis. Specifying the coordinates (components) of vectors of this basis in its current (rotated) position, in terms of the reference (non-rotated) coordinate axes, will completely describe the rotation. The three unit vectors ${\displaystyle \scriptstyle {\hat {\mathbf {u} }}}$, ${\displaystyle \scriptstyle {\hat {\mathbf {v} }}}$ and ${\displaystyle \scriptstyle {\hat {\mathbf {w} }}}$ which form the rotated basis each consist of 3 coordinates, yielding a total of 9 parameters. These parameters can be written as the elements of a Template:Gaps matrix ${\displaystyle \scriptstyle \mathbf {A} }$, called a rotation matrix. Typically, the coordinates of each of these vectors are arranged along a column of the matrix (however, beware that an alternative definition of rotation matrix exists and is widely used, where the vectors coordinates defined above are arranged by rows[1])

${\displaystyle {\mathbf {A} }=\left[{\begin{array}{ccc}{\hat {\mathbf {u} }}_{x}&{\hat {\mathbf {v} }}_{x}&{\hat {\mathbf {w} }}_{x}\\{\hat {\mathbf {u} }}_{y}&{\hat {\mathbf {v} }}_{y}&{\hat {\mathbf {w} }}_{y}\\{\hat {\mathbf {u} }}_{z}&{\hat {\mathbf {v} }}_{z}&{\hat {\mathbf {w} }}_{z}\\\end{array}}\right]}$

The elements of the rotation matrix are not all independent—as Euler's rotation theorem dictates, the rotation matrix has only three degrees of freedom. The rotation matrix has the following properties:

${\displaystyle \{1,e^{\pm i\theta }\}=\{1,\ \cos(\theta )+i\sin(\theta ),\ \cos(\theta )-i\sin(\theta )\}}$
where i is the standard imaginary unit with the property i2 = −1

The angle ${\displaystyle \scriptstyle \theta }$ which appears in the eigenvalue expression corresponds to the angle of the Euler axis and angle representation. The eigenvector corresponding with the eigenvalue of 1 is the accompanying Euler axis, since the axis is the only (nonzero) vector which remains unchanged by left-multiplying (rotating) it with the rotation matrix.

The above properties are equivalent to:

{\displaystyle {\begin{aligned}|{\hat {\mathbf {u} }}|=|{\hat {\mathbf {v} }}|&=1\\{\hat {\mathbf {u} }}\cdot {\hat {\mathbf {v} }}&=0\\{\hat {\mathbf {u} }}\times {\hat {\mathbf {v} }}&={\hat {\mathbf {w} }}\end{aligned}}}

which is another way of stating that ${\displaystyle \scriptstyle {\hat {\mathbf {u} }},\,{\hat {\mathbf {v} }},\,{\hat {\mathbf {w} }}}$ form a 3D orthonormal basis. Note that the statements above constitute a total of 6 conditions (the cross product contains 3), leaving the rotation matrix with just 3 degrees of freedom as required.

Two successive rotations represented by matrices ${\displaystyle \scriptstyle {\mathbf {A} }_{1}}$ and ${\displaystyle \scriptstyle {\mathbf {A} }_{2}}$ are easily combined as follows: ${\displaystyle \scriptstyle {\mathbf {A} }_{\text{total}}\;=\;{\mathbf {A} }_{2}{\mathbf {A} }_{1}}$ (Note the order, since the vector being rotated is multiplied from the right). The ease by which vectors can be rotated using a rotation matrix, as well as the ease of combining successive rotations, make the rotation matrix a very useful and popular way to represent rotations, even though it is less concise than other representations.

### Euler axis and angle (rotation vector)

A visualization of a rotation represented by an Euler axis and angle.

{{#invoke:main|main}} From Euler's rotation theorem we know that any rotation can be expressed as a single rotation about some axis. The axis is the unit vector (unique except for sign) which remains unchanged by the rotation. The magnitude of the angle is also unique, with its sign being determined by the sign of the rotation axis.

The axis can be represented as a three-dimensional unit vector ${\displaystyle \scriptstyle {\hat {\mathbf {e} }}\;=\;[e_{x}\ e_{y}\ e_{z}]^{\mathrm {T} }}$, and the angle by a scalar ${\displaystyle \scriptstyle \theta }$.

Since the axis is normalized, it has only two degrees of freedom. The angle adds the third degree of freedom to this rotation representation.

One may wish to express rotation as a rotation vector, a non-normalized three-dimensional vector the direction of which specifies the axis, and the length of which is ${\displaystyle \theta }$:

${\displaystyle v=\theta {\hat {\mathbf {e} }}}$

The rotation vector is in some contexts useful, as it represents a three-dimensional rotation with only three scalar values (its components), representing the three degrees of freedom. This is also true for representations based on sequences of three Euler angles (see below).

If the rotation angle ${\displaystyle \scriptstyle \theta }$ is zero, the axis is not uniquely defined. Combining two successive rotations, each represented by an Euler axis and angle, is not straightforward, and in fact does not satisfy the law of vector addition, which shows that finite rotations are not really vectors at all. It is best to employ the rotation matrix or quaternion notation, calculate the product, and then convert back to Euler axis and angle.

### Euler rotations

Euler rotations of the Earth. Intrinsic (green), Precession (blue) and Nutation (red)

{{#invoke:main|main}} The idea behind Euler rotations is to split the complete rotation of the coordinate system into three simpler constitutive rotations, called Precession, Nutation, and intrinsic rotation, being each one of them an increment on one of the Euler angles. Notice that the outer matrix will represent a rotation around one of the axes of the reference frame, and the inner matrix represents a rotation around one of the moving frame axis. The middle matrix represent a rotation around an intermediate axis called line of nodes.

Unfortunately, the definition of Euler angles is not unique and in the literature many different conventions are used. These conventions depend on the axes about which the rotations are carried out, and their sequence (since rotations are not commutative).

The convention being used is usually indicated by specifying the axes about which the consecutive rotations (before being composed) take place, referring to them by index (1, 2, 3) or letter (X, Y, Z). The engineering and robotics communities typically use 3-1-3 Euler angles. Notice that after composing the independent rotations, they do not rotate about their axis anymore. The most external matrix rotates the other two, leaving the second rotation matrix over the line of nodes, and the third one in a frame comoving with the body. There are Template:Gaps = 27 possible combinations of three basic rotations but only Template:Gaps = 12 of them can be used for representing arbitrary 3D rotations as Euler angles. These 12 combinations avoid consecutive rotations around the same axis (such as XXY) which would reduce the degrees of freedom that can be represented.

Therefore Euler angles are never expressed in terms of the external frame, or in terms of the co-moving rotated body frame, but in a mixture. Other conventions (e.g., rotation matrix or quaternions) are used to avoid this problem.

### Quaternions

{{#invoke:main|main}}

Quaternions, that form a four-dimensional vector space, have proven very useful in representing rotations due to several advantages above the other representations mentioned in this article.

A quaternion representation of rotation is written as a versor (normalized quaternion)

${\displaystyle {\hat {\mathbf {q} }}=[q_{1}\ q_{2}\ q_{3}\ q_{4}]^{\mathrm {T} }}$

In terms of the Euler axis

${\displaystyle {\hat {\mathbf {e} }}=[e_{x}\ e_{y}\ e_{z}]^{\mathrm {T} }}$

and angle

${\displaystyle \theta }$

this versor's components are expressed as follows:

{\displaystyle {\begin{aligned}q_{1}&=e_{x}\sin \left({\frac {\theta }{2}}\right)\\q_{2}&=e_{y}\sin \left({\frac {\theta }{2}}\right)\\q_{3}&=e_{z}\sin \left({\frac {\theta }{2}}\right)\\q_{4}&=\cos \left({\frac {\theta }{2}}\right)\end{aligned}}}

The above definition follows the convention as used in (Wertz 1980) and (Markley 2003). An alternative definition used in some publications defines the "scalar" term as the first quaternion element, with the other elements shifted down one position. (Coutsias 1999), (Schmidt 2001)

Inspection shows that the quaternion parametrization obeys the following constraint:

${\displaystyle q_{1}^{2}+q_{2}^{2}+q_{3}^{2}+q_{4}^{2}=1}$

The last term (in our definition) is often called the scalar term, which has its origin in quaternions when understood as the mathematical extension of the complex numbers, written as

${\displaystyle a+bi+cj+dk}$ with ${\displaystyle \{a,b,c,d\}\in {\mathbb {R} }}$

and where ${\displaystyle \scriptstyle \{i,\,j,\,k\}}$ are the hypercomplex numbers satisfying

${\displaystyle {\begin{array}{lclrlcl}i^{2}&=&j^{2}&=&k^{2}&=&-1\\ij&=&-ji&=&k&&\\jk&=&-kj&=&i&&\\ki&=&-ik&=&j&&\end{array}}}$

Quaternion multiplication, that is used to specify a composite rotation, is performed in the same manner as multiplication of complex numbers, except that the order of elements must be taken into account, since multiplication is not commutative. In matrix notation we can write quaternion multiplication as

${\displaystyle {\tilde {\mathbf {q} }}\otimes {\mathbf {q} }=\left[{\begin{array}{rrrr}q_{4}&q_{3}&-q_{2}&q_{1}\\-q_{3}&q_{4}&q_{1}&q_{2}\\q_{2}&-q_{1}&q_{4}&q_{3}\\-q_{1}&-q_{2}&-q_{3}&q_{4}\end{array}}\right]\left[{\begin{array}{c}{\tilde {q}}_{1}\\{\tilde {q}}_{2}\\{\tilde {q}}_{3}\\{\tilde {q}}_{4}\end{array}}\right]=\left[{\begin{array}{rrrr}{\tilde {q}}_{4}&-{\tilde {q}}_{3}&{\tilde {q}}_{2}&{\tilde {q}}_{1}\\{\tilde {q}}_{3}&{\tilde {q}}_{4}&-{\tilde {q}}_{1}&{\tilde {q}}_{2}\\-{\tilde {q}}_{2}&{\tilde {q}}_{1}&{\tilde {q}}_{4}&{\tilde {q}}_{3}\\-{\tilde {q}}_{1}&-{\tilde {q}}_{2}&-{\tilde {q}}_{3}&{\tilde {q}}_{4}\end{array}}\right]\left[{\begin{array}{c}q_{1}\\q_{2}\\q_{3}\\q_{4}\end{array}}\right]}$

Combining two consecutive quaternion rotations is therefore just as simple as using the rotation matrix. Remember that two successive rotation matrices, ${\displaystyle \scriptstyle {\mathbf {A} }_{1}}$ followed by ${\displaystyle \scriptstyle {\mathbf {A} }_{2}}$, are combined as follows:

${\displaystyle {\mathbf {A} }_{3}={\mathbf {A} }_{2}{\mathbf {A} }_{1}}$

We can represent this with quaternion parameters in a similarly concise way:

${\displaystyle {\mathbf {q} }_{3}={\mathbf {q} }_{2}\otimes {\mathbf {q} }_{1}}$

Quaternions are a very popular parametrization due to the following properties:

Like rotation matrices, quaternions must sometimes be re-normalized due to rounding errors, to make sure that they correspond to valid rotations. The computational cost of re-normalizing a quaternion, however, is much less than for normalizing a Template:Gaps matrix.

### Rodrigues parameters

Rodrigues parameters can be expressed in terms of Euler axis and angle as follows:

${\displaystyle {\mathbf {r} }={\hat {\mathbf {e} }}\theta }$

This has a discontinuity at 180° (π radians): each vector, r, with a norm of π radians represent the same rotation as −r.

Similarly, the Gibbs representation can be expressed as follows:

${\displaystyle {\mathbf {g} }={\hat {\mathbf {e} }}\tan \left({\frac {\theta }{2}}\right)}$

A rotation g followed by a rotation f in Gibbs representation has the form

${\displaystyle ({\mathbf {g} },{\mathbf {f} })={\frac {{\mathbf {g} }+{\mathbf {f} }-{\mathbf {f} }\times {\mathbf {g} }}{1-{\mathbf {g} }\cdot {\mathbf {f} }}}}$

The Gibbs vector has the advantage (or disadvantage, depending on context) that 180° rotations cannot be represented. (Even using floating point numbers that include infinity, rotation direction cannot be well-defined; for example, naively a 180° rotation about the axis (1, 1, 0) would be ${\displaystyle \scriptstyle (\infty ,\,\infty ,\,0)}$, which is the same representation as 180° rotation about (1, 0.0001, 0).)

Modified Rodrigues parameters (MRPs) can be expressed in terms of Euler axis and angle by:

${\displaystyle {\mathbf {p} }={\hat {\mathbf {e} }}\tan \left({\frac {\theta }{4}}\right)}$

The modified Rodrigues parameterization shares many characteristics with the rotation vector parametrization, including the occurrence of discontinuous jumps in the parameter space when incrementing the rotation.

### Cayley–Klein parameters

{{#invoke:main|main}} See definition at Wolfram Mathworld.

## Conversion formulae between formalisms

{{#invoke:main|main}}

### Rotation matrix ↔ Euler angles

The Euler angles ${\displaystyle \scriptstyle (\phi ,\,\theta ,\,\psi )}$ can be extracted from the rotation matrix ${\displaystyle \scriptstyle \mathbf {A} }$ by inspecting the rotation matrix in analytical form.

Using the x-convention, the 3-1-3 Euler angles ${\displaystyle \scriptstyle \phi }$, ${\displaystyle \scriptstyle \theta }$ and ${\displaystyle \scriptstyle \psi }$ (around the ${\displaystyle \scriptstyle Z}$, ${\displaystyle \scriptstyle X}$ and again the ${\displaystyle \scriptstyle Z}$-axis) can be obtained as follows:

{\displaystyle {\begin{aligned}\phi &=\operatorname {arctan2} (A_{31},A_{32})\\\theta &=\arccos(A_{33})\\\psi &=-\operatorname {arctan2} (A_{13},A_{23})\end{aligned}}}

Note that ${\displaystyle \scriptstyle \operatorname {arctan2} (a,\,b)}$ is equivalent to ${\displaystyle \scriptstyle \arctan(a/b)}$ where it also takes into account the quadrant that the point ${\displaystyle \scriptstyle (a,\,b)}$ is in; see atan2.

When implementing the conversion, one has to take into account several situations:[2]

The rotation matrix ${\displaystyle \scriptstyle \mathbf {A} }$ is generated from the Euler angles by multiplying the three matrices generated by rotations about the axes.

${\displaystyle {\mathbf {A} }={\mathbf {A} }_{3}{\mathbf {A} }_{2}{\mathbf {A} }_{1}={\mathbf {A} }_{Z}{\mathbf {A} }_{Y}{\mathbf {A} }_{X}}$

The axes of the rotation depend on the specific convention being used. For the x-convention the rotations are about the ${\displaystyle \scriptstyle X}$, ${\displaystyle \scriptstyle Y}$ and ${\displaystyle \scriptstyle Z}$ axes with angles ${\displaystyle \scriptstyle \phi }$, ${\displaystyle \scriptstyle \theta }$ and ${\displaystyle \scriptstyle \psi }$, the individual matrices are as follows:

{\displaystyle {\begin{aligned}{\mathbf {A} }_{X}&=\left[{\begin{array}{ccc}1&0&0\\0&\cos \phi &\sin \phi \\0&-\sin \phi &\cos \phi \end{array}}\right]\\{\mathbf {A} }_{Y}&=\left[{\begin{array}{ccc}\cos \theta &0&-\sin \theta \\0&1&0\\\sin \theta &0&\cos \theta \end{array}}\right]\\{\mathbf {A} }_{Z}&=\left[{\begin{array}{ccc}\cos \psi &\sin \psi &0\\-\sin \psi &\cos \psi &0\\0&0&1\end{array}}\right]\end{aligned}}}

This yields

${\displaystyle {\begin{array}{lcl}{\mathbf {A} }&=&{\begin{bmatrix}\cos \theta \cos \psi &\cos \phi \sin \psi +\sin \phi \sin \theta \cos \psi &\sin \phi \sin \psi -\cos \phi \sin \theta \cos \psi \\-\cos \theta \sin \psi &\cos \phi \cos \psi -\sin \phi \sin \theta \sin \psi &\sin \phi \cos \psi +\cos \phi \sin \theta \sin \psi \\\sin \theta &-\sin \phi \cos \theta &\cos \phi \cos \theta \\\end{bmatrix}}\end{array}}}$

Note: This is valid for a right-hand system, which is the convention used in almost all engineering and physics disciplines.

### Rotation matrix ↔ Euler axis/angle

{{ safesubst:#invoke:Unsubst||$N=Merge from |date=__DATE__ |$B= Template:MboxTemplate:DMCTemplate:Merge partner }} If the Euler angle ${\displaystyle \scriptstyle \theta }$ is not a multiple of ${\displaystyle \scriptstyle \pi }$, the Euler axis ${\displaystyle \scriptstyle {\hat {\mathbf {e} }}\;=\;[e_{1}\ e_{2}\ e_{3}]^{\mathrm {T} }}$ and angle ${\displaystyle \scriptstyle \theta }$ can be computed from the elements of the rotation matrix ${\displaystyle \scriptstyle \mathbf {A} }$ as follows:

{\displaystyle {\begin{aligned}\theta &=\arccos \left({\frac {1}{2}}[A_{11}+A_{22}+A_{33}-1]\right)\\e_{1}&={\frac {A_{32}-A_{23}}{2\sin \theta }}\\e_{2}&={\frac {A_{13}-A_{31}}{2\sin \theta }}\\e_{3}&={\frac {A_{21}-A_{12}}{2\sin \theta }}\end{aligned}}}

Alternatively, the following method can be used:

Eigen-decomposition of the rotation matrix yields the eigenvalues 1, and ${\displaystyle \scriptstyle \cos \theta \pm i\sin \theta }$. The Euler axis is the eigenvector corresponding to the eigenvalue of 1, and the ${\displaystyle \scriptstyle \theta }$ can be computed from the remaining eigenvalues.

The Euler axis can be also found using Singular Value Decomposition since it is the normalized vector spanning the null-space of the matrix ${\displaystyle \scriptstyle I\,-\,A}$.

To convert the other way the rotation matrix corresponding to an Euler axis ${\displaystyle \scriptstyle {\hat {\mathbf {e} }}\;=\;[e_{1}\ e_{2}\ e_{3}]^{\mathrm {T} }}$ and angle ${\displaystyle \scriptstyle \theta }$ can be computed according to the Rodrigues' rotation formula (with appropriate modification) as follows:

${\displaystyle {\mathbf {A} }={\mathbf {I} }_{3}\cos \theta +(1-\cos \theta ){\hat {\mathbf {e} }}{\hat {\mathbf {e} }}^{\mathrm {T} }+[{\hat {\mathbf {e} }}]_{\times }\sin \theta }$
${\displaystyle [{\hat {\mathbf {e} }}]_{\times }=\left[{\begin{array}{ccc}0&-e_{3}&e_{2}\\e_{3}&0&-e_{1}\\-e_{2}&e_{1}&0\end{array}}\right]}$

is the cross-product matrix.

This expands to...

${\displaystyle A_{11}=(1-\cos \theta )e_{1}^{2}+\cos \theta }$
${\displaystyle A_{12}=(1-\cos \theta )e_{1}e_{2}-e_{3}\sin \theta }$
${\displaystyle A_{13}=(1-\cos \theta )e_{1}e_{3}+e_{2}\sin \theta }$
${\displaystyle A_{21}=(1-\cos \theta )e_{2}e_{1}+e_{3}\sin \theta }$
${\displaystyle A_{22}=(1-\cos \theta )e_{2}^{2}+\cos \theta }$
${\displaystyle A_{23}=(1-\cos \theta )e_{2}e_{3}-e_{1}\sin \theta }$
${\displaystyle A_{31}=(1-\cos \theta )e_{3}e_{1}-e_{2}\sin \theta }$
${\displaystyle A_{32}=(1-\cos \theta )e_{3}e_{2}+e_{1}\sin \theta }$
${\displaystyle A_{33}=(1-\cos \theta )e_{3}^{2}+\cos \theta }$

### Rotation matrix ↔ quaternion

When computing a quaternion from the rotation matrix there is a sign ambiguity, since ${\displaystyle \scriptstyle {\mathbf {q} }}$ and ${\displaystyle \scriptstyle -{\mathbf {q} }}$ represent the same rotation.

One way of computing the quaternion ${\displaystyle \scriptstyle {\mathbf {q} }\;=\;[q_{1}\ q_{2}\ q_{3}\ q_{4}]^{\mathrm {T} }}$ from the rotation matrix ${\displaystyle \scriptstyle \mathbf {A} }$ is as follows:

{\displaystyle {\begin{aligned}q_{4}&={\frac {1}{2}}{\sqrt {1+A_{11}+A_{22}+A_{33}}}\\q_{1}&={\frac {1}{4q_{4}}}(A_{32}-A_{23})\\q_{2}&={\frac {1}{4q_{4}}}(A_{13}-A_{31})\\q_{3}&={\frac {1}{4q_{4}}}(A_{21}-A_{12})\end{aligned}}}

There are three other mathematically equivalent ways to compute ${\displaystyle \scriptstyle {\mathbf {q} }}$. Numerical inaccuracy can be reduced by avoiding situations in which the denominator is close to zero. One of the other three methods looks as follows:[3]

{\displaystyle {\begin{aligned}q_{1}&={\frac {1}{2}}{\sqrt {1+A_{11}-A_{22}-A_{33}}}\\q_{2}&={\frac {1}{4q_{1}}}(A_{12}+A_{21})\\q_{3}&={\frac {1}{4q_{1}}}(A_{13}+A_{31})\\q_{4}&={\frac {1}{4q_{1}}}(A_{32}-A_{23})\end{aligned}}}

The rotation matrix corresponding to the quaternion ${\displaystyle \scriptstyle {\mathbf {q} }\;=\;[q_{1}\ q_{2}\ q_{3}\ q_{4}]^{\mathrm {T} }}$ can be computed as follows:

${\displaystyle {\mathbf {A} }=(q_{4}^{2}-{\check {\mathbf {q} }}^{\mathrm {T} }{\check {\mathbf {q} }}){\mathbf {I} }_{3}+2{\check {\mathbf {q} }}{\check {\mathbf {q} }}^{\mathrm {T} }+2q_{4}{\mathbf {\mathcal {Q}} }}$

with ${\displaystyle \scriptstyle {\mathbf {I} }_{3}}$ the Template:Gaps identity matrix, and

${\displaystyle {\check {\mathbf {q} }}=\left[{\begin{array}{c}q_{1}\\q_{2}\\q_{3}\end{array}}\right],\ \ \ {\mathbf {\mathcal {Q}} }=\left[{\begin{array}{ccc}0&-q_{3}&q_{2}\\q_{3}&0&-q_{1}\\-q_{2}&q_{1}&0\end{array}}\right]}$

which gives

${\displaystyle {\mathbf {A} }=\left[{\begin{array}{ccc}1-2q_{2}^{2}-2q_{3}^{2}&2(q_{1}q_{2}-q_{3}q_{4})&2(q_{1}q_{3}+q_{2}q_{4})\\2(q_{1}q_{2}+q_{3}q_{4})&1-2q_{1}^{2}-2q_{3}^{2}&2(q_{2}q_{3}-q_{1}q_{4})\\2(q_{1}q_{3}-q_{2}q_{4})&2(q_{1}q_{4}+q_{2}q_{3})&1-2q_{1}^{2}-2q_{2}^{2}\end{array}}\right]}$

or equivalently

${\displaystyle {\mathbf {A} }=\left[{\begin{array}{ccc}-1+2q_{1}^{2}+2q_{4}^{2}&2(q_{1}q_{2}-q_{3}q_{4})&2(q_{1}q_{3}+q_{2}q_{4})\\2(q_{1}q_{2}+q_{3}q_{4})&-1+2q_{2}^{2}+2q_{4}^{2}&2(q_{2}q_{3}-q_{1}q_{4})\\2(q_{1}q_{3}-q_{2}q_{4})&2(q_{1}q_{4}+q_{2}q_{3})&-1+2q_{3}^{2}+2q_{4}^{2}\end{array}}\right]}$

### Euler angles ↔ quaternion

{{#invoke:main|main}} We will consider the x-convention 3-1-3 Euler Angles for the following algorithm. The terms of the algorithm depend on the convention used.

We can compute the quaternion ${\displaystyle \scriptstyle \mathbf {q} =[q_{1}\ q_{2}\ q_{3}\ q_{4}]^{\mathrm {T} }}$ from the Euler angles ${\displaystyle \scriptstyle (\phi ,\,\theta ,\,\psi )}$ as follows:

{\displaystyle {\begin{aligned}q_{1}&=\cos \left({\frac {\phi -\psi }{2}}\right)\sin \left({\frac {\theta }{2}}\right)\\q_{2}&=\sin \left({\frac {\phi -\psi }{2}}\right)\sin \left({\frac {\theta }{2}}\right)\\q_{3}&=\sin \left({\frac {\phi +\psi }{2}}\right)\cos \left({\frac {\theta }{2}}\right)\\q_{4}&=\cos \left({\frac {\phi +\psi }{2}}\right)\cos \left({\frac {\theta }{2}}\right)\end{aligned}}}

Given the rotation quaternion ${\displaystyle \scriptstyle \mathbf {q} =[q_{1}\ q_{2}\ q_{3}\ q_{4}]^{\mathrm {T} }}$, the x-convention 3-1-3 Euler angles ${\displaystyle \scriptstyle (\phi ,\,\theta ,\,\psi )}$ can be computed by

{\displaystyle {\begin{aligned}\phi &=\arctan 2((q_{1}q_{3}+q_{2}q_{4}),-(q_{2}q_{3}-q_{1}q_{4}))\\\theta &=\arccos(-q_{1}^{2}-q_{2}^{2}+q_{3}^{2}+q_{4}^{2})\\\psi &=\arctan 2((q_{1}q_{3}-q_{2}q_{4}),(q_{2}q_{3}+q_{1}q_{4}))\end{aligned}}}

### Euler axis/angle ↔ quaternion

Given the Euler axis ${\displaystyle \scriptstyle {\hat {\mathbf {e} }}}$ and angle ${\displaystyle \scriptstyle \theta }$, the quaternion

${\displaystyle {\mathbf {q} }=[q_{1}\ q_{2}\ q_{3}\ q_{4}]^{\mathrm {T} }}$

can be computed by

{\displaystyle {\begin{aligned}q_{1}&={\hat {e}}_{1}\sin \left({\frac {\theta }{2}}\right)\\q_{2}&={\hat {e}}_{2}\sin \left({\frac {\theta }{2}}\right)\\q_{3}&={\hat {e}}_{3}\sin \left({\frac {\theta }{2}}\right)\\q_{4}&=\cos \left({\frac {\theta }{2}}\right)\end{aligned}}}
{\displaystyle {\begin{aligned}{\hat {\mathbf {e} }}&={\frac {\check {\mathbf {q} }}{\|{\check {\mathbf {q} }}\|}}\\\theta &=2\arccos(q_{4})\end{aligned}}}

## Conversion formulae for derivatives

### Rotation matrix ↔ angular velocities

The angular velocity vector ${\displaystyle \scriptstyle {\mathbf {\omega } }\;=\;(\omega _{x},\,\omega _{y},\,\omega _{z})}$ can be extracted from the derivative of the rotation matrix ${\displaystyle \scriptstyle {\frac {d{\mathbf {A} }}{dt}}}$ by the following relation:

${\displaystyle [{\mathbf {\omega } }]_{\times }=\left[{\begin{array}{ccc}0&-\omega _{z}&\omega _{y}\\\omega _{z}&0&-\omega _{x}\\-\omega _{y}&\omega _{x}&0\end{array}}\right]={\frac {d{\mathbf {A} }}{dt}}{\mathbf {A} }^{\mathrm {T} }}$

The derivation is adapted from [4] as follows:

For any vector ${\displaystyle \scriptstyle r_{0}}$ consider ${\displaystyle \scriptstyle r(t)\;=\;{\mathbf {A} }(t)r_{0}}$ and differentiate it:

${\displaystyle {\frac {dr}{dt}}={\frac {d{\mathbf {A} }}{dt}}r_{0}={\frac {d{\mathbf {A} }}{dt}}{\mathbf {A} }^{\mathrm {T} }(t)r(t)}$

The derivative of a vector is the linear velocity of its tip. Since A is a rotation matrix, by definition the length of ${\displaystyle \scriptstyle r(t)}$ is always equal to the length of ${\displaystyle \scriptstyle r_{0}}$, and hence it does not change with time. Thus, when ${\displaystyle \scriptstyle r(t)}$ rotates, its tip moves along a circle, and the linear velocity of its tip is tangential to the circle; i.e., always perpendicular to ${\displaystyle \scriptstyle r(t)}$. In this specific case, the relationship between the linear velocity vector and the angular velocity vector is

${\displaystyle {\frac {dr}{dt}}={\mathbf {\omega } }(t)\times r(t)=[{\mathbf {\omega } }]_{\times }r(t)}$ (see circular motion and Cross product).

By the transitivity of the above mentioned equations,

${\displaystyle {\frac {d{\mathbf {A} }}{dt}}{\mathbf {A} }^{\mathrm {T} }(t)r(t)=[{\mathbf {\omega } }]_{\times }r(t)}$

which implies (Q.E.D.),

${\displaystyle {\frac {d{\mathbf {A} }}{dt}}{\mathbf {A} }^{\mathrm {T} }(t)=[{\mathbf {\omega } }]_{\times }}$

### Quaternion ↔ angular velocities

The angular velocity vector ${\displaystyle \scriptstyle {\mathbf {\omega } }\;=\;(\omega _{x},\,\omega _{y},\,\omega _{z})}$ can be obtained from the derivative of the quaternion ${\displaystyle \scriptstyle {\frac {d{\mathbf {q} }}{dt}}}$ as follows:[5]

${\displaystyle \left[{\begin{array}{c}\omega _{x}\\\omega _{y}\\\omega _{z}\\0\end{array}}\right]=2{\frac {d\mathbf {q} }{dt}}\otimes {\tilde {\mathbf {q} }}}$

Conversely, the derivative of the quaternion is

${\displaystyle {\frac {d\mathbf {q} }{dt}}={\frac {1}{2}}\left[{\begin{array}{c}\omega _{x}\\\omega _{y}\\\omega _{z}\\0\end{array}}\right]\otimes \mathbf {q} }$

## Rotors in a geometric algebra

{{ safesubst:#invoke:Unsubst||$N=Merge to |date=__DATE__ |$B= Template:MboxTemplate:DMCTemplate:Merge partner }} The formalism of geometric algebra (GA) provides an extension and interpretation of the quaternion method. Central to GA is the geometric product of vectors, an extension of the traditional inner and cross products, given by

${\displaystyle ab=a\cdot b+a\wedge b}$

where the symbol ${\displaystyle \scriptstyle \wedge }$ denotes the outer product. This product of vectors ${\displaystyle \scriptstyle a,\,b}$ produces two terms: a scalar part from the inner product and a bivector part from the outer product. This bivector describes the plane perpendicular to what the cross product of the vectors would return.

Bivectors in GA have some unusual properties compared to vectors. Under the geometric product, bivectors have negative square: the bivector ${\displaystyle \scriptstyle {\hat {x}}{\hat {y}}}$ describes the ${\displaystyle \scriptstyle xy}$-plane. Its square is ${\displaystyle \scriptstyle ({\hat {x}}{\hat {y}})^{2}\;=\;{\hat {x}}{\hat {y}}{\hat {x}}{\hat {y}}}$. Because the unit basis vectors are orthogonal to each other, the geometric product reduces to the antisymmetric outer product – ${\displaystyle \scriptstyle {\hat {x}}}$ and ${\displaystyle \scriptstyle {\hat {y}}}$ can be swapped freely at the cost of a factor of −1. The square reduces to ${\displaystyle \scriptstyle -{\hat {x}}{\hat {x}}{\hat {y}}{\hat {y}}\;=\;-1}$ since the basis vectors themselves square to +1.

This result holds generally for all bivectors, and as a result the bivector plays a role similar to the imaginary unit. Geometric algebra uses bivectors in its analogue to the quaternion, the rotor, given by ${\displaystyle \scriptstyle R\;=\;\exp \left({\frac {-{\hat {B}}\theta }{2}}\right)\;=\;\cos {\frac {\theta }{2}}\,-\,{\hat {B}}\sin {\frac {\theta }{2}}}$, where ${\displaystyle \scriptstyle {\hat {B}}}$ is a unit bivector that describes the plane of rotation. Because ${\displaystyle \scriptstyle {\hat {B}}}$ squares to −1, the power series expansion of ${\displaystyle \scriptstyle R}$ generates the trigonometric functions. The rotation formula that maps a vector ${\displaystyle \scriptstyle a}$ to a rotated vector ${\displaystyle \scriptstyle b}$ is then

${\displaystyle b=RaR^{\dagger }}$

where ${\displaystyle \scriptstyle R^{\dagger }\;=\;\exp \left({\frac {1}{2}}{\hat {B}}\theta \right)\;=\;\cos {\frac {1}{2}}\theta \,+\,{\hat {B}}\sin {\frac {1}{2}}\theta }$ is the reverse of ${\displaystyle \scriptstyle R}$ (reversing the order of the vectors in ${\displaystyle \scriptstyle B}$ is equivalent to changing its sign).

Example. A rotation about the axis ${\displaystyle \scriptstyle {\hat {v}}\;=\;{\frac {1}{\sqrt {3}}}({\hat {x}}\,+\,{\hat {y}}\,+\,{\hat {z}})}$ can be accomplished by converting ${\displaystyle \scriptstyle {\hat {v}}}$ to its dual bivector, ${\displaystyle \scriptstyle {\hat {B}}\;=\;{\hat {x}}{\hat {y}}{\hat {z}}{\hat {v}}\;=\;i{\hat {v}}}$, where ${\displaystyle \scriptstyle i\;=\;{\hat {x}}{\hat {y}}{\hat {z}}}$ is the unit volume element, the only trivector (pseudoscalar) in three-dimensional space. The result is ${\displaystyle \scriptstyle {\hat {B}}\;=\;{\frac {1}{\sqrt {3}}}({\hat {y}}{\hat {z}}\,+\,{\hat {z}}{\hat {x}}\,+\,{\hat {x}}{\hat {y}})}$. In three-dimensional space, however, it is often simpler to leave the expression for ${\displaystyle \scriptstyle {\hat {B}}\;=\;i{\hat {v}}}$, using the fact that ${\displaystyle \scriptstyle i}$ commutes with all objects in 3D and also squares to −1. A rotation of the ${\displaystyle \scriptstyle {\hat {x}}}$ vector in this plane by an angle ${\displaystyle \scriptstyle \theta }$ is then

${\displaystyle {\hat {x}}'=R{\hat {x}}R^{\dagger }=e^{-i{\hat {v}}{\frac {\theta }{2}}}{\hat {x}}e^{i{\hat {v}}{\frac {\theta }{2}}}={\hat {x}}\cos ^{2}{\frac {\theta }{2}}+i({\hat {x}}{\hat {v}}-{\hat {v}}{\hat {x}})\cos {\frac {\theta }{2}}\sin {\frac {\theta }{2}}+{\hat {v}}{\hat {x}}{\hat {v}}\sin ^{2}{\frac {\theta }{2}}}$

Recognizing that ${\displaystyle \scriptstyle i({\hat {x}}{\hat {v}}\,-\,{\hat {v}}{\hat {x}})\;=\;2i({\hat {x}}\,\wedge \,{\hat {v}})}$ and that ${\displaystyle \scriptstyle -{\hat {v}}{\hat {x}}{\hat {v}}}$ is the reflection of ${\displaystyle \scriptstyle {\hat {x}}}$ about the plane perpendicular to ${\displaystyle \scriptstyle {\hat {v}}}$ gives a geometric interpretation to the rotation operation: the rotation preserves the components that are parallel to ${\displaystyle \scriptstyle {\hat {v}}}$ and changes only those that are perpendicular. The terms are then computed:

{\displaystyle {\begin{aligned}{\hat {v}}{\hat {x}}{\hat {v}}&={\frac {1}{3}}(-{\hat {x}}+2{\hat {y}}+2{\hat {z}})\\2i{\hat {x}}\wedge {\hat {v}}&=2i{\frac {1}{\sqrt {3}}}({\hat {x}}{\hat {y}}+{\hat {x}}{\hat {z}})={\frac {2}{\sqrt {3}}}({\hat {y}}-{\hat {z}})\end{aligned}}}

The result of the rotation is then

${\displaystyle {\hat {x}}'={\hat {x}}\left(\cos ^{2}{\frac {\theta }{2}}-{\frac {1}{3}}\sin ^{2}{\frac {\theta }{2}}\right)+{\frac {2}{3}}{\hat {y}}\sin {\frac {\theta }{2}}\left(\sin {\frac {\theta }{2}}+{\sqrt {3}}\cos {\frac {\theta }{2}}\right)+{\frac {2}{3}}{\hat {z}}\sin {\frac {\theta }{2}}\left(\sin {\frac {\theta }{2}}-{\sqrt {3}}\cos {\frac {\theta }{2}}\right)}$

A simple check on this result is the angle ${\displaystyle \scriptstyle \theta \;=\;{\frac {2}{3}}\pi }$. Such a rotation should map the ${\displaystyle \scriptstyle {\hat {x}}}$ to ${\displaystyle \scriptstyle {\hat {y}}}$. Indeed, the rotation reduces to

{\displaystyle {\begin{aligned}{\hat {x}}'&={\hat {x}}\left({\frac {1}{4}}-{\frac {1}{3}}{\frac {3}{4}}\right)+{\frac {2}{3}}{\hat {y}}{\frac {\sqrt {3}}{2}}\left({\frac {\sqrt {3}}{2}}+{\sqrt {3}}{\frac {1}{2}}\right)+{\frac {2}{3}}{\hat {z}}{\frac {\sqrt {3}}{2}}\left({\frac {\sqrt {3}}{2}}-{\sqrt {3}}{\frac {1}{2}}\right)\\&=0{\hat {x}}+{\hat {y}}+0{\hat {z}}={\hat {y}}\end{aligned}}}

exactly as expected. This rotation formula is valid not only for vectors but for any multivector. In addition, when Euler angles are used, the complexity of the operation is much reduced. Compounded rotations come from multiplying the rotors, so the total rotor from Euler angles is

${\displaystyle R=R_{\gamma '}R_{\beta '}R_{\alpha }=\exp \left({\frac {-i{\hat {z}}'\gamma }{2}}\right)\exp \left({\frac {-i{\hat {x}}'\beta }{2}}\right)\exp \left({\frac {-i{\hat {z}}\alpha }{2}}\right)}$

but ${\displaystyle \scriptstyle {\hat {x}}'\;=\;R_{\alpha }{\hat {x}}R_{\alpha }^{\dagger }}$ and ${\displaystyle \scriptstyle {\hat {z}}'\;=\;R_{\beta '}{\hat {z}}R_{\beta '}^{\dagger }}$. These rotors come back out of the exponentials like so:

${\displaystyle R_{\beta '}=\cos {\frac {\beta }{2}}-iR_{\alpha }{\hat {x}}R_{\alpha }^{\dagger }\sin {\frac {\beta }{2}}=R_{\alpha }R_{\beta }R_{\alpha }^{\dagger }}$

where ${\displaystyle \scriptstyle R_{\beta }}$ refers to rotation in the original coordinates. Similarly for the ${\displaystyle \scriptstyle \gamma }$ rotation, ${\displaystyle \scriptstyle R_{\gamma '}\;=\;R_{\beta '}R_{\gamma }R_{\beta '}^{\dagger }\;=\;R_{\alpha }R_{\beta }R_{\alpha }^{\dagger }R_{\gamma }R_{\alpha }R_{\beta }^{\dagger }R_{\alpha }^{\dagger }}$. Noting that ${\displaystyle \scriptstyle R_{\gamma }}$ and ${\displaystyle \scriptstyle R_{\alpha }}$ commute (rotations in the same plane must commute), and the total rotor becomes

${\displaystyle R=R_{\alpha }R_{\beta }R_{\gamma }}$

Thus, the compounded rotations of Euler angles become a series of equivalent rotations in the original fixed frame.

While rotors in geometric algebra work almost identically to quaternions in three dimensions, the power of this formalism is its generality: this method is appropriate and valid in spaces with any number of dimensions. In 3D, rotations have three degrees of freedom, a degree for each linearly independent plane (bivector) the rotation can take place in. It has been known that pairs of quaternions can be used to generate rotations in 4D, yielding six degrees of freedom, and the geometric algebra approach verifies this result: in 4D, there are six linearly independent bivectors that can be used as the generators of rotations.

## References

1. Rotation Matrix, http://mathworld.wolfram.com/RotationMatrix.html
2. Direct and inverse kinematics lecture notes, page 5
3. Template:Cite arxiv
4. [1] Physics - Mark Ioffe - W(t) in terms of matrices
5. [2] Physics - Kinematics - Angular Velocity
• Evangelos A. Coutsias and Louis Romero, (1999) The Quaternions with an application to Rigid Body Dynamics, Department of Mathematics and Statistics, University of New Mexico.
• F. Landis Markley, (2003) Attitude Error Representations for Kalman Filtering, Journal of Guidance, Control and Dynamics.
• H. Goldstein, (1980) Classical Mechanics, 2nd. ed., Addison–Wesley. ISBN 0-201-02918-9
• James R. Wertz, (1980) Spacecraft Attitude Determination and Control, D. Reidel Publishing Company. ISBN 90-277-1204-2
• J. Schmidt and H. Niemann, (2001) Using Quaternions for Parametrizing 3-D Rotations in Unconstrained Nonlinear Optimization, Vision, Modeling and Visualization (VMV01).
• Lev D. Landau and E. M. Lifshitz, (1976) Mechanics, 3rd. ed., Pergamon Press. ISBN 0-08-021022-8 (hardcover) and ISBN 0-08-029141-4 (softcover).
• Klumpp, A. R., Singularity-Free Extraction of a Quaternion from a Direction-Cosine Matrix, Journal of Spacecraft and Rockets, vol. 13, Dec. 1976, p. 754, 755.
• C. Doran and A. Lasenby, (2003) Geometric Algebra for Physicists, Cambridge University Press. ISBN 978-0-521-71595-9