Rotation formalisms in three dimensions

From HandWiki
Short description: Ways to represent 3D rotations

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 a 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. 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

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.

When representing a rotation as numbers in a computer, some people prefer the quaternion representation or the axis+angle representation, because they avoid the gimbal lock that can occur with Euler rotations.[1]

Formalism alternatives

Rotation matrix

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, û, and ŵ, that 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 3 × 3 matrix 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[2]) [math]\displaystyle{ \mathbf{A} = \begin{bmatrix} \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{bmatrix} }[/math]

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:

  • A is a real, orthogonal matrix, hence each of its rows or columns represents a unit vector.
  • The eigenvalues of A are [math]\displaystyle{ \left\{1, e^{\pm i\theta} \right\} = \{1,\ \cos\theta+i\sin\theta,\ \cos\theta-i\sin\theta\} }[/math] where i is the standard imaginary unit with the property i2 = −1
  • The determinant of A is +1, equivalent to the product of its eigenvalues.
  • The trace of A is 1 + 2 cos θ, equivalent to the sum of its eigenvalues.

The angle θ which appears in the eigenvalue expression corresponds to the angle of the Euler axis and angle representation. The eigenvector corresponding to 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 [math]\displaystyle{ \begin{align} |\hat{\mathbf u}| = |\hat{\mathbf v}| = |\hat{\mathbf w}| &= 1\\ \hat{\mathbf u} \cdot \hat{\mathbf v} &= 0\\ \hat{\mathbf u} \times \hat{\mathbf v} &= \hat{\mathbf w} \,, \end{align} }[/math] which is another way of stating that (û, , ŵ) form a 3D orthonormal basis. These statements comprise 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 A1 and A2 are easily combined as elements of a group, [math]\displaystyle{ \mathbf{A}_\text{total} = \mathbf{A}_2\mathbf{A}_1 }[/math] (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 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.

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 [math]\displaystyle{ \hat{\mathbf{e}} = \begin{bmatrix} e_x \\ e_y \\ e_z \end{bmatrix} }[/math] and the angle by a scalar θ.

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, or Euler vector, an un-normalized three-dimensional vector the direction of which specifies the axis, and the length of which is θ, [math]\displaystyle{ \mathbf{r} = \theta \hat{\mathbf{e}}\,. }[/math]

The rotation vector is useful in some contexts, 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 θ 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)

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 axes. The middle matrix represents a rotation around an intermediate axis called line of nodes.

However, 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 on a sphere are non-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 3 × 3 × 3 = 27 possible combinations of three basic rotations but only 3 × 2 × 2 = 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.

In aviation orientation of the aircraft is usually expressed as intrinsic Tait-Bryan angles following the z-y′-x convention, which are called heading, elevation, and bank (or synonymously, yaw, pitch, and roll).

Quaternions

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

A quaternion representation of rotation is written as a versor (normalized quaternion): [math]\displaystyle{ \hat{\mathbf{q}} =q_i\mathbf{i}+q_j\mathbf{j}+q_k\mathbf{k}+q_r = \begin{bmatrix} q_i \\ q_j \\ q_k \\ q_r \end{bmatrix} }[/math]

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

In terms of the Euler axis [math]\displaystyle{ \hat{\mathbf{e}} = \begin{bmatrix} e_x \\ e_y \\ e_z \end{bmatrix} }[/math]

and angle θ this versor's components are expressed as follows: [math]\displaystyle{ \begin{align} q_i &= e_x\sin\frac{\theta}{2}\\ q_j &= e_y\sin\frac{\theta}{2}\\ q_k &= e_z\sin\frac{\theta}{2}\\ q_r &= \cos\frac{\theta}{2} \end{align} }[/math]

Inspection shows that the quaternion parametrization obeys the following constraint: [math]\displaystyle{ q_i^2 + q_j^2 + q_k^2 + q_r^2 = 1 }[/math]

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 [math]\displaystyle{ a + b i + c j + d k \qquad \text{with } a, b, c, d \in \R }[/math] and where {i, j, k} are the hypercomplex numbers satisfying [math]\displaystyle{ \begin{array}{ccccccc} i^2 &=& j^2 &=& k^2 &=& -1\\ ij &=& -ji &=& k&&\\ jk &=& -kj &=& i&&\\ ki &=& -ik &=& j&& \end{array} }[/math]

Quaternion multiplication, which is used to specify a composite rotation, is performed in the same manner as multiplication of complex numbers, except that the order of the elements must be taken into account, since multiplication is not commutative. In matrix notation we can write quaternion multiplication as [math]\displaystyle{ \tilde{\mathbf{q}}\otimes\mathbf{q} = \begin{bmatrix} \;\;\, q_r & \;\;\, q_k & -q_j & \;\;\, q_i\\ -q_k & \;\;\, q_r & \;\;\, q_i & \;\;\, q_j\\ \;\;\, q_j & -q_i & \;\;\, q_r & \;\;\, q_k\\ -q_i & -q_j & -q_k & \;\;\, q_r \end{bmatrix} \begin{bmatrix} \tilde{q}_i\\ \tilde{q}_j\\ \tilde{q}_k\\ \tilde{q}_r \end{bmatrix} = \begin{bmatrix} \;\;\, \tilde{q}_r & -\tilde{q}_k & \;\;\, \tilde{q}_j & \;\;\, \tilde{q}_i\\ \;\;\, \tilde{q}_k & \;\;\, \tilde{q}_r & -\tilde{q}_i & \;\;\, \tilde{q}_j\\ -\tilde{q}_j & \;\;\, \tilde{q}_i & \;\;\, \tilde{q}_r & \;\;\, \tilde{q}_k\\ -\tilde{q}_i & -\tilde{q}_j & -\tilde{q}_k & \;\;\, \tilde{q}_r \end{bmatrix} \begin{bmatrix} q_i\\ q_j\\ q_k\\ q_r \end{bmatrix} }[/math]

Combining two consecutive quaternion rotations is therefore just as simple as using the rotation matrix. Just as two successive rotation matrices, A1 followed by A2, are combined as [math]\displaystyle{ \mathbf{A}_3 = \mathbf{A}_2\mathbf{A}_1, }[/math] we can represent this with quaternion parameters in a similarly concise way: [math]\displaystyle{ \mathbf{q}_3 = \mathbf{q}_2 \otimes \mathbf{q}_1 }[/math]

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

  • More compact than the matrix representation and less susceptible to round-off errors
  • The quaternion elements vary continuously over the unit sphere in 4, (denoted by S3) as the orientation changes, avoiding discontinuous jumps (inherent to three-dimensional parameterizations)
  • Expression of the rotation matrix in terms of quaternion parameters involves no trigonometric functions
  • It is simple to combine two individual rotations represented as quaternions using a quaternion product

Like rotation matrices, quaternions must sometimes be renormalized due to rounding errors, to make sure that they correspond to valid rotations. The computational cost of renormalizing a quaternion, however, is much less than for normalizing a 3 × 3 matrix.

Quaternions also capture the spinorial character of rotations in three dimensions. For a three-dimensional object connected to its (fixed) surroundings by slack strings or bands, the strings or bands can be untangled after two complete turns about some fixed axis from an initial untangled state. Algebraically, the quaternion describing such a rotation changes from a scalar +1 (initially), through (scalar + pseudovector) values to scalar −1 (at one full turn), through (scalar + pseudovector) values back to scalar +1 (at two full turns). This cycle repeats every 2 turns. After 2n turns (integer n > 0), without any intermediate untangling attempts, the strings/bands can be partially untangled back to the 2(n − 1) turns state with each application of the same procedure used in untangling from 2 turns to 0 turns. Applying the same procedure n times will take a 2n-tangled object back to the untangled or 0 turn state. The untangling process also removes any rotation-generated twisting about the strings/bands themselves. Simple 3D mechanical models can be used to demonstrate these facts.

Rodrigues vector

The Rodrigues vector (sometimes called the Gibbs vector, with coordinates called Rodrigues parameters)[3][4] can be expressed in terms of the axis and angle of the rotation as follows: [math]\displaystyle{ \mathbf{g} = \hat{\mathbf{e}}\tan\frac{\theta}{2} }[/math]

This representation is a higher-dimensional analog of the gnomonic projection, mapping unit quaternions from a 3-sphere onto the 3-dimensional pure-vector hyperplane.

It has a discontinuity at 180° (π radians): as any rotation vector r tends to an angle of π radians, its tangent tends to infinity.

A rotation g followed by a rotation f in the Rodrigues representation has the simple rotation composition form

[math]\displaystyle{ (\mathbf{g},\mathbf{f}) = \frac{\mathbf{g}+\mathbf{f}-\mathbf{f}\times\mathbf{g}}{1-\mathbf{g}\cdot\mathbf{f}} \,. }[/math]

Today, the most straightforward way to prove this formula is in the (faithful) doublet representation, where g = tan a, etc.

The combinatoric features of the Pauli matrix derivation just mentioned are also identical to the equivalent quaternion derivation below. Construct a quaternion associated with a spatial rotation R as, [math]\displaystyle{ S = \cos\frac{\phi}{2} + \sin\frac{\phi}{2} \mathbf{S}. }[/math] Then the composition of the rotation RB with RA is the rotation RC = RBRA, with rotation axis and angle defined by the product of the quaternions, [math]\displaystyle{ A=\cos\frac{\alpha}{2}+ \sin\frac{\alpha}{2}\mathbf{A}\quad \text{and} \quad B=\cos\frac{\beta}{2}+ \sin\frac{\beta}{2}\mathbf{B}, }[/math] that is [math]\displaystyle{ C = \cos\frac{\gamma}{2}+\sin\frac{\gamma}{2}\mathbf{C} = \left(\cos\frac{\beta}{2}+\sin\frac{\beta}{2}\mathbf{B}\right) \left(\cos\frac{\alpha}{2} + \sin\frac{\alpha}{2}\mathbf{A}\right). }[/math]

Expand this quaternion product to [math]\displaystyle{ \cos\frac{\gamma}{2}+\sin\frac{\gamma}{2} \mathbf{C} = \left(\cos\frac{\beta}{2}\cos\frac{\alpha}{2} - \sin\frac{\beta}{2}\sin\frac{\alpha}{2} \mathbf{B}\cdot \mathbf{A}\right) + \left(\sin\frac{\beta}{2} \cos\frac{\alpha}{2} \mathbf{B} + \sin\frac{\alpha}{2} \cos\frac{\beta}{2} \mathbf{A} + \sin\frac{\beta}{2} \sin\frac{\alpha}{2} \mathbf{B}\times \mathbf{A}\right). }[/math]

Divide both sides of this equation by the identity resulting from the previous one, [math]\displaystyle{ \cos\frac{\gamma}{2} = \cos\frac{\beta}{2}\cos\frac{\alpha}{2} - \sin\frac{\beta}{2}\sin\frac{\alpha}{2} \mathbf{B}\cdot \mathbf{A}, }[/math] and evaluate

[math]\displaystyle{ \tan\frac{\gamma}{2} \mathbf{C} = \frac{\tan\frac{\beta}{2}\mathbf{B} + \tan\frac{\alpha}{2} \mathbf{A} + \tan\frac{\beta}{2}\tan\frac{\alpha}{2} \mathbf{B}\times \mathbf{A}}{1 - \tan\frac{\beta}{2}\tan\frac{\alpha}{2} \mathbf{B}\cdot \mathbf{A}}. }[/math]

This is Rodrigues' formula for the axis of a composite rotation defined in terms of the axes of the two component rotations. He derived this formula in 1840 (see page 408).[3] The three rotation axes A, B, and C form a spherical triangle and the dihedral angles between the planes formed by the sides of this triangle are defined by the rotation angles.

Modified Rodrigues parameters (MRPs) can be expressed in terms of Euler axis and angle by [math]\displaystyle{ \mathbf{p} = \hat{\mathbf{e}}\tan\frac{\theta}{4}\,. }[/math] Its components can be expressed in terms of the components of a unit quaternion representing the same rotation as [math]\displaystyle{ p_{x,y,z} = \frac{q_{i,j,k}}{1 + q_r}\,. }[/math]

The modified Rodrigues vector is a stereographic projection mapping unit quaternions from a 3-sphere onto the 3-dimensional pure-vector hyperplane. The projection of the opposite quaternion q results in a different modified Rodrigues vector ps than the projection of the original quaternion q. Comparing components one obtains that [math]\displaystyle{ p^s_{x,y,z} = \frac{-q_{i,j,k}}{1-q_r} =\frac{-p_{x,y,z}}{\mathbf{p}^2}\,. }[/math] Notably, if one of these vectors lies inside the unit 3-sphere, the other will lie outside.

Cayley–Klein parameters

See definition at Wolfram Mathworld.

Higher-dimensional analogues

Vector transformation law

Active rotations of a 3D vector p in Euclidean space around an axis n over an angle η can be easily written in terms of dot and cross products as follows:

[math]\displaystyle{ \mathbf{p}' = p_\parallel \mathbf{n} + \cos{\eta} \, \mathbf{p}_\perp + \sin{\eta} \, \mathbf{p} \wedge \mathbf{n} }[/math] wherein [math]\displaystyle{ p_\parallel = \mathbf{p} \cdot \mathbf{n} }[/math] is the longitudinal component of p along n, given by the dot product, [math]\displaystyle{ \mathbf{p}_\perp = \mathbf{p} - (\mathbf{p} \cdot \mathbf{n}) \mathbf{n} }[/math] is the transverse component of p with respect to n, and [math]\displaystyle{ \mathbf{p} \wedge \mathbf{n} }[/math]

is the cross product of p with n.

The above formula shows that the longitudinal component of p remains unchanged, whereas the transverse portion of p is rotated in the plane perpendicular to n. This plane is spanned by the transverse portion of p itself and a direction perpendicular to both p and n. The rotation is directly identifiable in the equation as a 2D rotation over an angle η.

Passive rotations can be described by the same formula, but with an inverse sign of either η or n.

Conversion formulae between formalisms

Rotation matrix ↔ Euler angles

The Euler angles (φ, θ, ψ) can be extracted from the rotation matrix A by inspecting the rotation matrix in analytical form.

Rotation matrix → Euler angles (z-x-z extrinsic)

Using the x-convention, the 3-1-3 extrinsic Euler angles φ, θ and ψ (around the z-axis, x-axis and again the [math]\displaystyle{ Z }[/math]-axis) can be obtained as follows: [math]\displaystyle{ \begin{align} \phi &= \operatorname{atan2}\left(A_{31}, A_{32}\right)\\ \theta &= \arccos\left(A_{33}\right)\\ \psi &= -\operatorname{atan2}\left(A_{13}, A_{23}\right) \end{align} }[/math]

Note that atan2(a, b) is equivalent to arctan a/b where it also takes into account the quadrant that the point (b, a) is in; see atan2.

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

  • There are generally two solutions in the interval [−π, π]3. The above formula works only when θ is within the interval [0, π].
  • For the special case A33 = 0, φ and ψ will be derived from A11 and A12.
  • There are infinitely many but countably many solutions outside of the interval [−π, π]3.
  • Whether all mathematical solutions apply for a given application depends on the situation.

Euler angles (z-y′-x intrinsic) → rotation matrix

The rotation matrix A is generated from the 3-2-1 intrinsic Euler angles by multiplying the three matrices generated by rotations about the axes. [math]\displaystyle{ \mathbf{A} = \mathbf{A}_3\mathbf{A}_2\mathbf{A}_1 = \mathbf{A}_Z\mathbf{A}_Y\mathbf{A}_X }[/math]

The axes of the rotation depend on the specific convention being used. For the x-convention the rotations are about the x-, y- and z-axes with angles ϕ, θ and ψ, the individual matrices are as follows: [math]\displaystyle{ \begin{align} \mathbf{A}_X &= \begin{bmatrix} 1 & 0 & 0\\ 0 & \cos\phi & -\sin\phi\\ 0 & \sin\phi & \cos\phi \end{bmatrix} \\[5px] \mathbf{A}_Y &= \begin{bmatrix} \cos\theta & 0 & \sin\theta\\ 0 & 1 & 0\\ -\sin\theta & 0 & \cos\theta \end{bmatrix} \\[5px] \mathbf{A}_Z &= \begin{bmatrix} \cos\psi & -\sin\psi & 0\\ \sin\psi & \cos\psi & 0\\ 0 & 0 & 1 \end{bmatrix} \end{align} }[/math]

This yields [math]\displaystyle{ \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} }[/math] Note: This is valid for a right-hand system, which is the convention used in almost all engineering and physics disciplines.

The interpretation of these right-handed rotation matrices is that they express coordinate transformations (passive) as opposed to point transformations (active). Because A expresses a rotation from the local frame 1 to the global frame 0 (i.e., A encodes the axes of frame 1 with respect to frame 0), the elementary rotation matrices are composed as above. Because the inverse rotation is just the rotation transposed, if we wanted the global-to-local rotation from frame 0 to frame 1, we would write [math]\displaystyle{ \mathbf{A}^\mathsf{T} = (\mathbf{A}_Z\mathbf{A}_Y\mathbf{A}_X)^\mathsf{T} = \mathbf{A}_X^\mathsf{T}\mathbf{A}_Y^\mathsf{T}\mathbf{A}_Z^\mathsf{T}\,. }[/math]

Rotation matrix ↔ Euler axis/angle

If the Euler angle θ is not a multiple of π, the Euler axis ê and angle θ can be computed from the elements of the rotation matrix A as follows: [math]\displaystyle{ \begin{align} \theta &= \arccos\frac{A_{11}+A_{22}+A_{33}-1}{2}\\ 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{align} }[/math]

Alternatively, the following method can be used:

Eigendecomposition of the rotation matrix yields the eigenvalues 1 and cos θ ± i sin θ. The Euler axis is the eigenvector corresponding to the eigenvalue of 1, and θ 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 IA.

To convert the other way the rotation matrix corresponding to an Euler axis ê and angle θ can be computed according to Rodrigues' rotation formula (with appropriate modification) as follows: [math]\displaystyle{ \mathbf{A} = \mathbf{I}_3\cos\theta + (1-\cos\theta)\hat{\mathbf{e}}\hat{\mathbf{e}}^\mathsf{T} + \left[\hat{\mathbf{e}}\right]_{\times} \sin\theta }[/math]

with I3 the 3 × 3 identity matrix, and [math]\displaystyle{ \left[\hat{\mathbf{e}}\right]_{\times} = \begin{bmatrix} 0 & -e_3 & e_2\\ e_3 & 0 & -e_1\\ -e_2 & e_1 & 0 \end{bmatrix} }[/math]

is the cross-product matrix.

This expands to: [math]\displaystyle{ \begin{align} A_{11} &= (1-\cos\theta) e_1^2 + \cos\theta \\ A_{12} &= (1-\cos\theta) e_1 e_2 - e_3 \sin\theta \\ A_{13} &= (1-\cos\theta) e_1 e_3 + e_2 \sin\theta \\ A_{21} &= (1-\cos\theta) e_2 e_1 + e_3 \sin\theta \\ A_{22} &= (1-\cos\theta) e_2^2 + \cos\theta \\ A_{23} &= (1-\cos\theta) e_2 e_3 - e_1 \sin\theta \\ A_{31} &= (1-\cos\theta) e_3 e_1 - e_2 \sin\theta \\ A_{32} &= (1-\cos\theta) e_3 e_2 + e_1 \sin\theta \\ A_{33} &= (1-\cos\theta) e_3^2 + \cos\theta \end{align} }[/math]


Rotation matrix ↔ quaternion

When computing a quaternion from the rotation matrix there is a sign ambiguity, since q and q represent the same rotation.

One way of computing the quaternion [math]\displaystyle{ \mathbf{q} = \begin{bmatrix} q_i \\ q_j \\ q_k \\ q_r \end{bmatrix} = q_i\mathbf{i}+q_j\mathbf{j}+q_k\mathbf{k}+q_r }[/math] from the rotation matrix A is as follows: [math]\displaystyle{ \begin{align} q_r &= \frac{1}{2}\sqrt{1+A_{11}+A_{22}+A_{33}}\\ q_i &= \frac{1}{4q_r}\left(A_{32}- A_{23}\right)\\ q_j &= \frac{1}{4q_r}\left(A_{13}- A_{31}\right)\\ q_k &= \frac{1}{4q_r}\left(A_{21}- A_{12}\right) \end{align} }[/math]

There are three other mathematically equivalent ways to compute 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:[6][7] [math]\displaystyle{ \begin{align} q_i &= \frac{1}{2}\sqrt{1 + A_{11} - A_{22} - A_{33}}\\ q_j &= \frac{1}{4q_i}\left(A_{12} + A_{21}\right)\\ q_k &= \frac{1}{4q_i}\left(A_{13} + A_{31}\right)\\ q_r &= \frac{1}{4q_i}\left(A_{32} - A_{23}\right) \end{align} }[/math]

The rotation matrix corresponding to the quaternion q can be computed as follows: [math]\displaystyle{ \mathbf{A} = \left(q_r^2 - \check{\mathbf{q}}^\mathsf{T}\check{\mathbf{q}}\right)\mathbf{I}_3 + 2\check{\mathbf{q}}\check{\mathbf{q}}^\mathsf{T} + 2q_r\mathbf{\mathcal{Q}} }[/math] where [math]\displaystyle{ \check{\mathbf{q}} = \begin{bmatrix} q_i\\q_j\\q_k\end{bmatrix} \,, \quad \mathbf{\mathcal{Q}} = \begin{bmatrix} 0 & -q_k & q_j\\ q_k & 0 & -q_i\\ -q_j & q_i & 0 \end{bmatrix} }[/math] which gives [math]\displaystyle{ \mathbf{A} = \begin{bmatrix} 1 - 2q_j^2 - 2q_k^2 & 2\left(q_iq_j - q_kq_r\right) & 2\left(q_iq_k + q_jq_r\right)\\ 2\left(q_iq_j + q_kq_r\right) & 1 - 2q_i^2- 2 q_k^2 & 2\left(q_jq_k - q_iq_r\right)\\ 2\left(q_iq_k - q_jq_r\right) & 2\left(q_jq_k + q_iq_r\right) & 1 - 2q_i^2 - 2q_j^2 \end{bmatrix} }[/math]

or equivalently [math]\displaystyle{ \mathbf{A} = \begin{bmatrix} -1 + 2q_i^2 + 2q_r^2 & 2\left(q_iq_j - q_kq_r\right) & 2\left(q_iq_k + q_jq_r\right)\\ 2\left(q_iq_j + q_kq_r\right) & -1 + 2q_j^2 + 2q_r^2 & 2\left(q_jq_k - q_iq_r\right)\\ 2\left(q_iq_k - q_jq_r\right) & 2\left(q_jq_k + q_iq_r\right) & -1 + 2q_k^2 + 2q_r^2 \end{bmatrix} }[/math]

Euler angles ↔ quaternion

Euler angles (z-x-z extrinsic) → quaternion

We will consider the x-convention 3-1-3 extrinsic Euler angles for the following algorithm. The terms of the algorithm depend on the convention used.

We can compute the quaternion [math]\displaystyle{ \mathbf{q} = \begin{bmatrix} q_i \\ q_j \\ q_k \\ q_r \end{bmatrix} = q_i\mathbf{i}+q_j\mathbf{j}+q_k\mathbf{k}+q_r }[/math] from the Euler angles (ϕ, θ, ψ) as follows:

[math]\displaystyle{ \begin{align} q_i &= \cos\frac{\phi - \psi}{2}\sin\frac{\theta}{2}\\ q_j &= \sin\frac{\phi - \psi}{2}\sin\frac{\theta}{2}\\ q_k &= \sin\frac{\phi + \psi}{2}\cos\frac{\theta}{2}\\ q_r &= \cos\frac{\phi + \psi}{2}\cos\frac{\theta}{2} \end{align} }[/math]

Euler angles (z-y′-x intrinsic) → quaternion

A quaternion equivalent to yaw (ψ), pitch (θ) and roll (ϕ) angles. or intrinsic Tait–Bryan angles following the z-y′-x convention, can be computed by

[math]\displaystyle{ \begin{align} q_i &= \sin \frac{\phi}{2} \cos \frac{\theta}{2} \cos \frac{\psi}{2} - \cos \frac{\phi}{2} \sin \frac{\theta}{2} \sin \frac{\psi}{2}\\ q_j &= \cos \frac{\phi}{2} \sin \frac{\theta}{2} \cos \frac{\psi}{2} + \sin \frac{\phi}{2} \cos \frac{\theta}{2} \sin \frac{\psi}{2}\\ q_k &= \cos \frac{\phi}{2} \cos \frac{\theta}{2} \sin \frac{\psi}{2} - \sin \frac{\phi}{2} \sin \frac{\theta}{2} \cos \frac{\psi}{2}\\ q_r &= \cos \frac{\phi}{2} \cos \frac{\theta}{2} \cos \frac{\psi}{2} + \sin \frac{\phi}{2} \sin \frac{\theta}{2} \sin \frac{\psi}{2} \end{align} }[/math]

Quaternion → Euler angles (z-x-z extrinsic)

Given the rotation quaternion [math]\displaystyle{ \mathbf{q} = \begin{bmatrix} q_i \\ q_j \\ q_k \\ q_r \end{bmatrix} = q_i\mathbf{i}+q_j\mathbf{j}+q_k\mathbf{k}+q_r \,, }[/math] the x-convention 3-1-3 extrinsic Euler Angles (φ, θ, ψ) can be computed by

[math]\displaystyle{ \begin{align} \phi &= \operatorname{atan2}\left(\left(q_iq_k + q_jq_r\right), -\left(q_jq_k - q_iq_r\right)\right)\\ \theta &= \arccos\left(-q_i^2 - q_j^2 + q_k^2+q_r^2\right)\\ \psi &= \operatorname{atan2}\left(\left(q_iq_k - q_jq_r\right), \left(q_jq_k + q_iq_r\right)\right) \end{align} }[/math]

Quaternion → Euler angles (z-y′-x intrinsic)

Given the rotation quaternion [math]\displaystyle{ \mathbf{q} = \begin{bmatrix} q_i \\ q_j \\ q_k \\ q_r \end{bmatrix} = q_i\mathbf{i}+q_j\mathbf{j}+q_k\mathbf{k}+q_r \,, }[/math] yaw, pitch and roll angles, or intrinsic Tait–Bryan angles following the z-y′-x convention, can be computed by

[math]\displaystyle{ \begin{align} \text{roll} &= \operatorname{atan2} \left(2\left(q_r q_i + q_j q_k\right),1 - 2\left(q_i^2 + q_j^2\right)\right) \\ \text{pitch} &= \arcsin \left(2\left(q_r q_j - q_k q_i\right)\right) \\ \text{yaw} &= \operatorname{atan2} \left(2\left(q_r q_k + q_i q_j\right),1 - 2\left(q_j^2 + q_k^2\right)\right) \end{align} }[/math]

Euler axis–angle ↔ quaternion

Given the Euler axis ê and angle θ, the quaternion [math]\displaystyle{ \mathbf{q} = \begin{bmatrix} q_i \\ q_j \\ q_k \\ q_r \end{bmatrix} = q_i\mathbf{i}+q_j\mathbf{j}+q_k\mathbf{k}+q_r \,, }[/math]

can be computed by [math]\displaystyle{ \begin{align} q_i &= \hat{e}_1\sin\frac{\theta}{2} \\ q_j &= \hat{e}_2\sin\frac{\theta}{2} \\ q_k &= \hat{e}_3\sin\frac{\theta}{2} \\ q_r &= \cos\frac{\theta}{2} \end{align} }[/math]

Given the rotation quaternion q, define [math]\displaystyle{ \check{\mathbf{q}} = \begin{bmatrix} q_i \\ q_j \\ q_k \end{bmatrix}\,. }[/math] Then the Euler axis ê and angle θ can be computed by [math]\displaystyle{ \begin{align} \hat{\mathbf{e}} &= \frac{\check{\mathbf{q}}}{\left\|\check{\mathbf{q}}\right\|} \\ \theta &= 2\arccos q_r \end{align} }[/math]

Rotation matrix ↔ Rodrigues vector

Rodrigues vector → Rotation matrix

Since the definition of the Rodrigues vector can be related to rotation quaternions:[math]\displaystyle{ \begin{cases} g_i = \dfrac{q_i}{q_r} = e_x \tan\left(\dfrac{\theta}{2}\right) \\ g_j = \dfrac{q_j}{q_r} = e_y \tan\left(\dfrac{\theta}{2}\right)\\ g_k = \dfrac{q_k}{q_r} = e_z \tan\left(\dfrac{\theta}{2}\right) \end{cases} }[/math]By making use of the following property[math]\displaystyle{ 1 = q_r^2 + q_i^2 + q_j^2 + q_k^2 = q_r^2 \left(1 + \frac{q_i^2}{q_r^2} + \frac{q_j^2}{q_r^2} + \frac{q_k^2}{q_r^2}\right) = q_r^2 \left(1 + g_i^2 + g_j^2 + g_k^2\right) }[/math]The formula can be obtained by factoring q2r from the final expression obtained for quaternions:

[math]\displaystyle{ \mathbf{A} = q_r^2 \begin{bmatrix} \frac{1}{q_r^2} - 2\frac{q_j^2}{q_r^2} - 2\frac{q_k^2}{q_r^2} & 2\left(\frac{q_i}{q_r}\frac{q_j}{q_r} - \frac{q_k}{q_r}\right) & 2\left(\frac{q_i}{q_r}\frac{q_k}{q_r} + \frac{q_j}{q_r}\right)\\ 2\left(\frac{q_i}{q_r}\frac{q_j}{q_r} + \frac{q_k}{q_r}\right) & \frac{1}{q_r^2} - 2\frac{q_i^2}{q_r^2} - 2 \frac{q_k^2}{q_r^2} & 2\left(\frac{q_j}{q_r}\frac{q_k}{q_r} - \frac{q_i}{q_r}\right)\\ 2\left(\frac{q_i}{q_r}\frac{q_k}{q_r} - \frac{q_j}{q_r}\right) & 2\left(\frac{q_j}{q_r}\frac{q_k}{q_r} + \frac{q_i}{q_r}\right) & \frac{1}{q_r^2} - 2\frac{q_i^2}{q_r^2} - 2\frac{q_j^2}{q_r^2} \end{bmatrix} }[/math]

Leading to the final formula:

[math]\displaystyle{ \mathbf{A} = \frac{1}{1+g_i^2+g_j^2+g_k^2} \begin{bmatrix} 1 + g_i^2 - g_j^2 - g_k^2 & 2\left(g_i g_j - g_k\right) & 2\left(g_i g_k + g_j\right)\\ 2\left(g_i g_j + g_k\right) &1 - g_i^2 + g_j^2 - g_k^2 & 2\left(g_j g_k - g_i\right)\\ 2\left(g_i g_k - g_j\right) & 2\left(g_j g_k + g_i\right) &1 - g_i^2 - g_j^2 + g_k^2 \end{bmatrix} }[/math]

Conversion formulae for derivatives

Rotation matrix ↔ angular velocities

The angular velocity vector [math]\displaystyle{ \boldsymbol{\omega} = \begin{bmatrix} \omega_x \\ \omega_y \\ \omega_z \end{bmatrix} }[/math] can be extracted from the time derivative of the rotation matrix dA/dt by the following relation: [math]\displaystyle{ [\boldsymbol{\omega}]_\times = \begin{bmatrix} 0 & -\omega_z & \omega_y \\ \omega_z & 0 & -\omega_x \\ -\omega_y & \omega_x & 0 \end{bmatrix} = \frac{\mathrm{d}\mathbf{A}}{\mathrm{d}t}\mathbf{A}^\mathsf{T} }[/math]

The derivation is adapted from Ioffe[8] as follows:

For any vector r0, consider r(t) = A(t)r0 and differentiate it: [math]\displaystyle{ \frac{\mathrm{d}\mathbf{r}}{\mathrm{d}t} = \frac{\mathrm{d}\mathbf{A}}{\mathrm{d}t} \mathbf{r}_0 = \frac{\mathrm{d}\mathbf{A}}{\mathrm{d}t} \mathbf{A}^\mathsf{T}(t) \mathrm{r}(t) }[/math]

The derivative of a vector is the linear velocity of its tip. Since A is a rotation matrix, by definition the length of r(t) is always equal to the length of r0, and hence it does not change with time. Thus, when 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 r(t). In this specific case, the relationship between the linear velocity vector and the angular velocity vector is [math]\displaystyle{ \frac{\mathrm{d}\mathbf{r}}{\mathrm{d}t} = \boldsymbol{\omega}(t)\times \mathbf{r}(t) = [\boldsymbol{\omega}]_\times \mathbf{r}(t) }[/math] (see circular motion and cross product).

By the transitivity of the abovementioned equations, [math]\displaystyle{ \frac{\mathrm{d}\mathbf{A}}{\mathrm{d}t} \mathbf{A}^\mathsf{T}(t) \mathbf{r}(t) = [\boldsymbol{\omega}]_\times \mathbf{r}(t) }[/math]

which implies [math]\displaystyle{ \frac{\mathrm{d}\mathbf{A}}{\mathrm{d}t} \mathbf{A}^\mathsf{T}(t) = [\boldsymbol{\omega}]_\times }[/math]

Quaternion ↔ angular velocities

The angular velocity vector [math]\displaystyle{ \boldsymbol{\omega} = \begin{bmatrix} \omega_x \\ \omega_y \\ \omega_z \end{bmatrix} }[/math] can be obtained from the derivative of the quaternion dq/dt as follows:[9] [math]\displaystyle{ \begin{bmatrix} 0 \\ \omega_x \\ \omega_y \\ \omega_z \end{bmatrix} = 2 \frac{\mathrm{d}\mathbf{q}}{\mathrm{d}t}\tilde{\mathbf{q}} }[/math] where is the conjugate (inverse) of q.

Conversely, the derivative of the quaternion is [math]\displaystyle{ \frac{\mathrm{d}\mathbf{q}}{\mathrm{d}t} = \frac{1}{2}\begin{bmatrix} 0 \\ \omega_x \\ \omega_y \\ \omega_z \end{bmatrix}\mathbf{q} \,. }[/math]

Rotors in a geometric algebra

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 [math]\displaystyle{ \mathbf{ab} = \mathbf{a} \cdot \mathbf{b} + \mathbf{a} \wedge \mathbf{b} }[/math]

where the symbol denotes the exterior product or wedge product. This product of vectors a, and b produces two terms: a scalar part from the inner product and a bivector part from the wedge 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 a negative square: the bivector x̂ŷ describes the xy-plane. Its square is (x̂ŷ)2 = x̂ŷx̂ŷ. Because the unit basis vectors are orthogonal to each other, the geometric product reduces to the antisymmetric outer product – and ŷ can be swapped freely at the cost of a factor of −1. The square reduces to x̂x̂ŷŷ = −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 [math]\displaystyle{ \mathbf{R} = \exp\left(\frac{-\hat\mathbf{B}\theta}{2}\right) = \cos \frac{\theta}{2} - \hat\mathbf{B} \sin \frac{\theta}{2}\,, }[/math] where is a unit bivector that describes the plane of rotation. Because squares to −1, the power series expansion of R generates the trigonometric functions. The rotation formula that maps a vector a to a rotated vector b is then [math]\displaystyle{ \mathbf{b} = \mathbf{R a R}^\dagger }[/math] where [math]\displaystyle{ \mathbf{R}^\dagger = \exp\left(\frac{1}{2}\hat\mathbf{B} \theta\right) = \cos \frac{\theta}{2} + \hat\mathbf{B} \sin \frac{\theta}{2} }[/math] is the reverse of [math]\displaystyle{ \scriptstyle R }[/math] (reversing the order of the vectors in [math]\displaystyle{ B }[/math] is equivalent to changing its sign).

Example. A rotation about the axis [math]\displaystyle{ \hat \mathbf{v} = \frac{1}{\sqrt 3}\left(\hat \mathbf{x} + \hat \mathbf{y} + \hat \mathbf{z}\right) }[/math] can be accomplished by converting to its dual bivector, [math]\displaystyle{ \hat \mathbf{B} = \hat \mathbf{x} \hat \mathbf{y} \hat \mathbf{z} \hat \mathbf{v} = \mathbf{i} \hat \mathbf{v} \,, }[/math] where i = x̂ŷẑ is the unit volume element, the only trivector (pseudoscalar) in three-dimensional space. The result is [math]\displaystyle{ \hat \mathbf{B} = \frac{1}{\sqrt 3}\left(\hat \mathbf{y} \hat \mathbf{z} + \hat \mathbf{z} \hat \mathbf{x} + \hat \mathbf{x} \hat \mathbf{y}\right) \,. }[/math]

In three-dimensional space, however, it is often simpler to leave the expression for = iv̂, using the fact that i commutes with all objects in 3D and also squares to −1. A rotation of the vector in this plane by an angle θ is then

[math]\displaystyle{ \hat \mathbf{x}' = \mathbf{R} \hat \mathbf{x} \mathbf{R}^\dagger = e^{-i\hat \mathbf{v} \frac{\theta}{2}} \hat \mathbf{x} e^{i \hat \mathbf{v} \frac{\theta}{2}} = \hat \mathbf{x} \cos^2 \frac{\theta}{2} + \mathbf{i} \left(\hat \mathbf{x} \hat \mathbf{v} - \hat \mathbf{v} \hat \mathbf{x}\right) \cos \frac{\theta}{2} \sin \frac{\theta}{2} + \hat \mathbf{v} \hat \mathbf{x} \hat \mathbf{v} \sin^2 \frac{\theta}{2} }[/math]

Recognizing that [math]\displaystyle{ \mathbf{i} (\hat \mathbf{x} \hat \mathbf{v} - \hat \mathbf{v} \hat \mathbf{x}) = 2\mathbf{i} (\hat \mathbf{x} \wedge \hat \mathbf{v}) }[/math] and that v̂x̂v̂ is the reflection of about the plane perpendicular to gives a geometric interpretation to the rotation operation: the rotation preserves the components that are parallel to and changes only those that are perpendicular. The terms are then computed: [math]\displaystyle{ \begin{align} \hat \mathbf{v} \hat \mathbf{x} \hat \mathbf{v} &= \frac{1}{3} \left(-\hat \mathbf{x} + 2 \hat \mathbf{y} + 2 \hat \mathbf{z}\right) \\ 2\mathbf{i} \hat \mathbf{x} \wedge \hat \mathbf{v} &= 2\mathbf{i} \frac{1}{\sqrt 3} \left(\hat \mathbf{x} \hat \mathbf{y} + \hat \mathbf{x} \hat \mathbf{z}\right) = \frac{2}{\sqrt 3} \left(\hat \mathbf{y} - \hat \mathbf{z}\right) \end{align} }[/math]

The result of the rotation is then [math]\displaystyle{ \hat \mathbf{x}' = \hat \mathbf{x} \left(\cos^2 \frac{\theta}{2} - \frac{1}{3} \sin^2 \frac{\theta}{2}\right) + \frac{2}{3} \hat \mathbf{y} \sin \frac{\theta}{2} \left(\sin \frac{\theta}{2} + \sqrt{3} \cos \frac{\theta}{2}\right) + \frac{2}{3} \hat \mathbf{z} \sin \frac{\theta}{2} \left(\sin \frac{\theta}{2} - \sqrt{3} \cos \frac{\theta}{2}\right) }[/math]

A simple check on this result is the angle θ = 2/3π. Such a rotation should map to ŷ. Indeed, the rotation reduces to [math]\displaystyle{ \begin{align} \hat \mathbf{x}' &= \hat \mathbf{x}\left(\frac{1}{4} - \frac{1}{3} \frac{3}{4}\right) + \frac{2}{3} \hat \mathbf{y} \frac{\sqrt 3}{2} \left(\frac{\sqrt 3}{2} + \sqrt{3}\frac{1}{2}\right) + \frac{2}{3} \hat \mathbf{z} \frac{\sqrt 3}{2} \left(\frac{\sqrt 3}{2} - \sqrt{3}\frac{1}{2}\right) \\ &= 0 \hat \mathbf{x} + \hat \mathbf{y} + 0 \hat \mathbf{z} = \hat \mathbf{y} \end{align} }[/math]

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 [math]\displaystyle{ \mathbf{R} = \mathbf{R}_{\gamma'} \mathbf{R}_{\beta'} \mathbf{R}_\alpha = \exp\left(\frac{-\mathbf{i} \hat \mathbf{z}' \gamma}{2}\right) \exp\left(\frac{-\mathbf{i} \hat \mathbf{x}' \beta}{2}\right) \exp\left(\frac{-\mathbf{i} \hat \mathbf{z} \alpha}{2}\right) }[/math] but [math]\displaystyle{ \begin{align} \hat \mathbf{x}' &= \mathbf{R}_\alpha \hat \mathbf{x} \mathbf{R}_\alpha^\dagger \quad \text{and} \\ \hat \mathbf{z}' &= \mathbf{R}_{\beta'} \hat \mathbf{z} \mathbf{R}_{\beta'}^\dagger \,. \end{align} }[/math] These rotors come back out of the exponentials like so: [math]\displaystyle{ \mathbf{R}_{\beta'} = \cos \frac{\beta}{2} - \mathbf{i} \mathbf{R}_\alpha \hat \mathbf{x} \mathbf{R}_\alpha^\dagger \sin \frac{\beta}{2} = \mathbf{R}_\alpha \mathbf{R}_\beta \mathbf{R}_\alpha^\dagger }[/math] where Rβ refers to rotation in the original coordinates. Similarly for the γ rotation, [math]\displaystyle{ \mathbf{R}_{\gamma'} = \mathbf{R}_{\beta'} \mathbf{R}_\gamma \mathbf{R}_{\beta'}^\dagger = \mathbf{R}_\alpha \mathbf{R}_\beta \mathbf{R}_\alpha^\dagger \mathbf{R}_\gamma \mathbf{R}_\alpha \mathbf{R}_\beta^\dagger \mathbf{R}_\alpha^\dagger \,. }[/math] Noting that Rγ and Rα commute (rotations in the same plane must commute), and the total rotor becomes [math]\displaystyle{ \mathbf{R} = \mathbf{R}_\alpha \mathbf{R}_\beta \mathbf{R}_\gamma }[/math]

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.

Angle-angle-angle

Rotations can be modeled as an axis and an angle; as illustrated with a gyroscope which has an axis through the rotor, and the amount of spin around that axis demonstrated by the rotation of the rotor; this rotation can be expressed as angle ∗ (axis) where axis is a unit vector specifying the direction of the rotor axis. From the origin, in any direction, is the same rotation axis, with the scale of the angle equivalent to the distance from the origin. From any other point in space, similarly the same direction vector applied relative to the orientation represented by the starting point rather than the origin applies the same change around the same axes that the unit vector specifies. The angle ∗ axis scaling each point gives a unique coordinate in angle-angle-angle notation. The difference between two coordinates immediately yields the single axis of rotation and angle between the two orientations.

The natural log of a quaternion represents curving space by 3 angles around 3 axles of rotation, and is expressed in arc-length; similar to Euler angles, but order independent.[10] There is a Lie product formula definition of the addition of rotations, which is that they are sum of infinitesimal steps of each rotation applied in series; this would imply that rotations are the result of all rotations in the same instant are applied, rather than a series of rotations applied subsequently.

The axes of rotation are aligned to the standard Cartesian x, y, z axes. These rotations may be simply added and subtracted, especially when the frames being rotated are fixed to each other as in IK chains. Differences between two objects that are in the same reference frame are found by simply subtracting their orientations. Rotations that are applied from external sources, or are from sources relative to the current rotation still require multiplications, application of the Rodriguez Formula is provided.

The rotation from each axle coordinate represent rotating the plane perpendicular to the specified axis simultaneously with all other axles. Although the measures can be considered in angles, the representation is actually the arc-length of the curve; an angle implies a rotation around a point, where a curvature is a delta applied to the current point in an inertial direction.

Just an observational note: log quaternions have rings, or octaves of rotations; that is for rotations greater than 4π have related curves. Curvatures of things that approach this boundary appear to chaotically jump orbits.

For 'human readable' angles the 1-norm can be used to rescale the angles to look more 'appropriate':

[math]\displaystyle{ \mathbf{Q} = \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} }[/math] Other related values are immediately derivable: [math]\displaystyle{ \begin{align} \|\mathbf{V}\|\text{ or }\|\mathbf{V}\|_2 &= \sqrt{XX+YY+ZZ}\\[6pt] \|\mathbf{V}\|_1 &= |X|+|Y|+|Z| \end{align} }[/math] The total angle of rotation: [math]\displaystyle{ \theta = \|\mathbf{V}\| }[/math] The axis of rotation: [math]\displaystyle{ \text{Axis}(\ln \mathbf{Q}) = \begin{bmatrix} \frac{X} \theta \\ \frac{Y} \theta \\ \frac{Z} \theta \end{bmatrix} }[/math]

Quaternion representation

[math]\displaystyle{ \mathbf{q} = \begin{bmatrix} \cos \frac \theta {2} \\ \sin \frac \theta {2} {\frac {X} {\|\mathbf{Q}\|}}\\ \sin \frac\theta{2} {\frac {Y} {\|\mathbf{Q}\|}}\\ \sin\frac\theta{2} {\frac {Z} {\|\mathbf{Q}\|}} \end{bmatrix} }[/math]

Basis matrix computation

This was built from rotating the vectors (1,0,0), (0,1,0), (0,0,1), and reducing constants.

Given an input Q = [X, Y, Z], [math]\displaystyle{ \begin{matrix} q_r = \cos\theta \\ q_i = \sin\theta \cdot \frac{X}{\|\mathbf{Q}\|}\\ q_j = \sin\theta \cdot \frac{Y}{\|\mathbf{Q}\|}\\ q_k = \sin\theta \cdot \frac{Z}{\|\mathbf{Q}\|} \end{matrix} }[/math]

Which are used to compute the resulting matrix [math]\displaystyle{ \begin{bmatrix} 1 - 2 q_j^2 - 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 - 2 q_i^2 - 2q_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 - 2 q_i^2 - 2 q_j^2 \end{bmatrix} }[/math]

Alternate basis calculation

Alternatively this can be used. Given A = [X, Y, Z], convert to angle-axis θ = ||A||, and [x, y, z] = A/||A||.

Compute some partial expressions:[math]\displaystyle{ \begin{matrix} x_y = xy(1-\cos \theta) & w_x = x\sin \theta & x_x = xx(1-\cos \theta) \\ y_z = yz(1-\cos \theta) & w_y = y\sin \theta & y_y = yy(1-\cos \theta) \\ x_z = xz(1-\cos \theta) & w_z = z\sin \theta & z_z = zz(1-\cos \theta) \end{matrix} }[/math]

Compute the resulting matrix: [math]\displaystyle{ \begin{bmatrix} \cos \theta+x_x & x_y + w_z & w_y + x_z \\ w_z + x_y & \cos \theta+y_y & y_z - w_x \\ x_z - w_y & w_x + y_z & \cos \theta+z_z \end{bmatrix} }[/math]

Expanded: [math]\displaystyle{ \begin{bmatrix} \cos \theta+x^2 (1-\cos \theta) & xy(1-\cos \theta) - z\sin \theta & y\sin \theta + xz(1-\cos \theta) \\ z\sin \theta + xy(1-\cos \theta) & \cos \theta+y^2 (1-\cos \theta) & yz(1-\cos \theta) - x\sin \theta \\ xz(1-\cos \theta) - y\sin \theta & x\sin \theta + yz(1-\cos \theta) & \cos \theta+z^{2}(1-\cos \theta) \end{bmatrix} }[/math]

Vector rotation

Rotate the vector v = (X, Y, Z) around the rotation vector Q = (X, Y, Z).

The angle of rotation will be θ = ||Q||.

Calculate the cosine of the angle times the vector to rotate, plus sine of the angle times the axis of rotation, plus one minus cosine of the angle times the dot product of the vector and rotation axis times the axis of rotation. [math]\displaystyle{ \mathbf{v}' = \cos(\theta) \mathbf{v} + \sin(\theta) \left( \frac \mathbf{Q} {\|\mathbf{Q}\|} \times \mathbf{v} \right) + (1-\cos(\theta) ) \left( \frac \mathbf{Q} {\|\mathbf{Q}\|} \cdot \mathbf{v} \right) \frac \mathbf{Q} {\|\mathbf{Q}\|} }[/math]

Some notes: the dot product includes the cosine of the angle between the vector being rotated and the axis of rotation times the length of v; the cross product includes the sine of the angle between the vector being rotated and the axis of rotation.

Rotate a rotation vector

Using Rodrigues' composite rotation formula, for a given rotation vector Q = (X, Y, Z), and another rotation vector A = (X′, Y′, Z′) to rotate the frame around.

From the initial rotation vectors, extract the angles and axes: [math]\displaystyle{ \begin{align} \theta &= \frac {\|\mathbf{Q}\|} {2} \\[6pt] \gamma &= \frac {\|\mathbf{A}\|} {2} \end{align} }[/math] Normalized axis of rotation for the current frame: [math]\displaystyle{ \hat\mathbf{Q} = \frac {\mathbf{Q}} {\|\mathbf{Q}\|} }[/math] Normalized axis of rotation to rotate the frame around: [math]\displaystyle{ \hat\mathbf{A} = \frac {\mathbf{A}} {\|\mathbf{A}\|} }[/math]

The result angle angle of the rotation is [math]\displaystyle{ \alpha = 2 \arccos \left( \cos(\theta) \cos(\gamma) + \sin(\theta) \sin(\gamma) \hat\mathbf{Q} \cdot \hat\mathbf{A} \right) }[/math] or [math]\displaystyle{ \alpha = 2 \arccos \left( {\cos( \theta - \gamma )} ( 1 - \hat\mathbf{Q} \cdot \hat\mathbf{A} ) + {\cos ( \theta + \gamma) } (1 + \hat\mathbf{Q} \cdot \hat\mathbf{A}) \right) }[/math]

The resultant, unnormalized axis of rotation: [math]\displaystyle{ \mathbf{r} = \sin\gamma \cos\theta \hat\mathbf{A} + \sin\theta \cos\gamma \hat\mathbf{Q} + \sin\theta \sin\gamma \hat\mathbf{A} \times \hat\mathbf{Q} }[/math] or [math]\displaystyle{ r = \left( \hat\mathbf{A} \times \hat\mathbf{Q} \right) \bigl( {\cos ({\theta} - \gamma)}-{ \cos ({ \theta} + \gamma)} \bigr) + \hat\mathbf{A} \bigl({\sin (\theta + \gamma)}+{\sin ( \theta - \gamma)}\bigr) + \hat\mathbf{Q} \bigl({\sin (\theta + \gamma)}-{\sin ({ \theta} - \gamma)}\bigr) }[/math]

The Rodrigues rotation formula would lead that the sin of above resulting angle can be used to normalize the vector, however this fails for large ranges; so normalize the result axis as any other vector. [math]\displaystyle{ \hat\mathbf{R} = \frac \mathbf{r} {\|\mathbf{r}\|} }[/math]

And the final frame rotation coordinate: [math]\displaystyle{ \mathbf{R} = \alpha \hat\mathbf{R} }[/math]

Spin rotation around a fixed axis

A rotation vector Q represents three axes; these may be used as a shorthand to rotate the rotation around using the above method to rotate a rotation vector. These expressions are best represented as code fragments.

Setup some constants used in other expressions. [math]\displaystyle{ \begin{align} n_x &= \frac{Q_x}{\|\mathbf{Q}\|} \\ n_y &= \frac{Q_y}{\|\mathbf{Q}\|} \\ n_z &= \frac{Q_z}{\|\mathbf{Q}\|} \\ \text{angle} &= \|\mathbf{Q}\| \\ s &= \sin(\text{angle}) \\ c_1 &= \cos(\text{angle}) \\ c &= 1 - c_1 \end{align} }[/math] using the above values: [math]\displaystyle{ \text{x-axis} = \left[x = c n_x^2 + c_1, \; y = c n_x n_y + s n_z, \; z = c n_x n_z - s n_y\right] }[/math] or [math]\displaystyle{ \text{y-axis} = \left[x = c n_y n_x - s n_z, \; y = c n_y^2 + c_1, \; z = c n_y n_z + s n_x\right] }[/math] or [math]\displaystyle{ \text{z-axis} = \left[x = c n_z n_x + s n_y, \; y = c n_z n_y - s n_x, \; z = c n_z^2 + c_1\right] }[/math]

Conversion from Basis Matrix

Compute the determinant of the matrix: [math]\displaystyle{ d = \frac{ \left( \text{basis}_{\text{right}_X} + \text{basis}_{\text{up}_Y} + \text{basis}_{\text{forward}_Z} \right) - 1 }{2} }[/math] Convert to the angle of rotation: [math]\displaystyle{ \begin{align} \theta &= 2 \arccos d \\[6pt] yz &= \text{basis}_{\text{up}_Z} - \text{basis}_{\text{forward}_Y} \\[6pt] xz &= \text{basis}_{\text{forward}_X} - \text{basis}_{\text{right}_Z} \\[6pt] xy &= \text{basis}_{\text{right}_Y} - \text{basis}_{\text{up}_X} \end{align} }[/math] Compute the normal factor: [math]\displaystyle{ \begin{align} \text{normal} &= \frac 1 \sqrt{yz ^2 + xz^2 + xy^2 } \\[6pt] \mathbf{n} &= \begin{bmatrix} yz \cdot \text{normal}\\ xz \cdot \text{normal}\\ xy \cdot \text{normal} \end{bmatrix} \end{align} }[/math]

the resulting angle-angle-angle is nθ.

Conversion from normal vector (Y)

Representation of a normal as a rotation, this assumes that the Y axis vector (0,1,0) is pointing up. If some other axis is considered primary, the coordinates can be simply swapped.

This assumes a normalized input vector in the direction of the normal [math]\displaystyle{ \mathbf{N} = \begin{bmatrix} \text{normal}_X \\ \text{normal}_Y \\ \text{normal}_Z \end{bmatrix} }[/math] The angle is simply the sum of the x- and z-coordinates (or y and x if Z is up, or y and z if X is up): [math]\displaystyle{ \text{angle} = |N_x| + |N_z| }[/math] if angle is 0, the job is done, result with (0,0,0) [math]\displaystyle{ r = \frac{1}{\text{angle}} }[/math] Some temporary values; these values are just partials referenced later: [math]\displaystyle{ \mathbf{t} = \begin{bmatrix} N_x \cdot r\\ N_y\\ N_z \cdot r \end{bmatrix} }[/math] Use the projected normal on the Y axis as the angle to rotate: [math]\displaystyle{ \begin{align} \text{target}_\text{angle} &= \arccos t_Y \\[6pt] \text{result} &= \begin{bmatrix} t_Z \cdot \text{target}_\text{angle}\\ 0\\ -t_X \cdot \text{target}_\text{angle} \end{bmatrix}\end{align} }[/math]

Align normal using basis

The default tangent and bitangent of rotations which only have their normal set, results in tangents and bi-tangents that are irregular. Alternatively build a basis matrix, and convert from basis using the above mentioned method. Compute the normal of the above, and the matrix to convert [math]\displaystyle{ \text{normal}_\text{twist} = {\sqrt { t_Z^2+t_X^2 }} }[/math] [math]\displaystyle{ \begin{bmatrix} \left(N_y \cdot \frac {-t_X }{ \text{normal}_\text{twist} }\right)&N_x&\frac {t_Z}{\text{normal}_\text{twist}} \\ \left(N_z \cdot \frac {t_Z}{\text{normal}_\text{twist}}\right)-\left(N_x \cdot \frac {-t_X }{ \text{normal}_\text{twist} } \right)&N_y&0\\ \left(-N_y \cdot \frac {t_Z}{\text{normal}_\text{twist}} \right)&N_z&\frac {-t_X }{ \text{normal}_\text{twist} } \end{bmatrix} }[/math] and then use the basis to log quaternion conversion as follows.

Align normal directly

Or This is the direct computation to result with a log quaternion; compute the above result vector and then... [math]\displaystyle{ \begin{align} t_{X_n} &= t_X\cdot \text{normal}_\text{twist} \\[4pt] t_{Z_n} &= t_Z\cdot \text{normal}_\text{twist} \\[4pt] s &= \sin( \text{target}_\text{angle} ) \\[4pt] c &= 1- \cos( \text{target}_\text{angle} ) \end{align} }[/math] This is the angle [math]\displaystyle{ \text{angle} = \arccos\left( \frac{\left( t_Y + 1 \right) \left( 1 - t_{X_n} \right) }{ 2 } - 1 \right); }[/math] These partial products are used below: [math]\displaystyle{ \begin{align} yz &= s \cdot n_X \\[4pt] xz &= \left( 2 - c \cdot \left(n_X^2 + n_Z^2\right) \right) \cdot t_{Z_n}\\[4pt] xy &= s \cdot n_X \cdot t_{Z_n} + s \cdot n_Z \cdot \left(1-t_{X_n}\right) \end{align} }[/math] Compute the normalized rotation vector (axle of rotation): [math]\displaystyle{ n = \begin{bmatrix} \frac{yz}{\sqrt{yz^2 + xz^2 + xy^2}}\\ \frac{xz}{\sqrt{yz^2 + xz^2 + xy^2}}\\ \frac{xy}{\sqrt{yz^2 + xz^2 + xy^2}} \end{bmatrix} }[/math]

and finally compute the resulting log quaternion. [math]\displaystyle{ \text{final}_\text{result} = \text{angle} \cdot {n} }[/math]

Conversion from axis-angle

This assumes the input axis a = [X, Y, Z] is normalized. If there is zero rotation, result with (0,0,0) [math]\displaystyle{ \theta = \text{angle} \quad ; \quad \text{result} = \theta * \mathbf{a} }[/math]

See also

References

  1. "Fiducial Marker Tracking for Augmented Reality".
  2. Weisstein, Eric W.. "Rotation Matrix". http://mathworld.wolfram.com/RotationMatrix.html. 
  3. 3.0 3.1 Rodrigues, Olinde (1840). "Des lois géometriques qui regissent les déplacements d'un systéme solide dans l'espace, et de la variation des coordonnées provenant de ces déplacement considérées indépendant des causes qui peuvent les produire". J. Math. Pures Appl. 5: 380–440.  online
  4. cf. J Willard Gibbs (1884). Elements of Vector Analysis, New Haven, p. 67
  5. Direct and inverse kinematics lecture notes, page 5
  6. Mebius, Johan (2007). "Derivation of the Euler–Rodrigues formula for three-dimensional rotations from the general formula for four-dimensional rotations". arXiv:math/0701759.
  7. Shuster, Malcolm D. (1993). "A Survey of Attitude Representations". Journal of the Astronautical Sciences 41 (4): 439–517. http://malcolmdshuster.com/Pub_1993h_J_Repsurv_scan.pdf. 
  8. [1] Physics - Mark Ioffe - W(t) in terms of matrices
  9. Quaternions and Rotation lecture notes, p. 14-15
  10. d3x0r. "STFRPhysics Repository". https://github.com/d3x0r/STFRPhysics. 

Further reading

External links