Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random | Template Test |  
Login
create new user
Username:
Password:
forget your password?
Main Menu
Sections

Meta

Talkback

Downloads

Information
quaternions and direction cosine matrices (Topic)

Quaternions and Direction Cosine Matrices

A unit quaternion and a proper direction cosine matrix are two representations of the same three dimensional orientation. Quaternions are compact and convenient for composition, interpolation, estimation, and numerical propagation. Direction cosine matrices act directly on coordinate columns and make frame transformations visually explicit.

PhysicsLibrary uses passive coordinate transformations as the canonical attitude interpretation. If

$\displaystyle {}^{B}q_A $

maps coordinates from frame $A$ into frame $B$, then

$\displaystyle {}^{B}v = {}^{B}q_A\,{}^{A}v\,({}^{B}q_A)^*.$ (1)

The corresponding direction cosine matrix is denoted

$\displaystyle {}^{B}C_A, $

and satisfies

$\displaystyle {}^{B}\mathbf v = {}^{B}C_A\,{}^{A}\mathbf v.$ (2)

The quaternion to matrix map is defined so that

$\displaystyle {}^{B}C_A = C({}^{B}q_A).$ (3)

Under the PhysicsLibrary convention, quaternion and DCM frame chains use the same written order:

$\displaystyle {}^{C}q_A = {}^{C}q_B\,{}^{B}q_A,$ (4)
$\displaystyle {}^{C}C_A = {}^{C}C_B\,{}^{B}C_A.$ (5)

This article derives the matrix from the quaternion sandwich, develops the inverse matrix to quaternion conversion, explains the transpose and conjugate relationship, and gives numerical checks for implementation.

Convention declaration

PhysicsLibrary uses Hamilton multiplication,

$\displaystyle \mathbf i\mathbf j=\mathbf k, \qquad \mathbf j\mathbf k=\mathbf i, \qquad \mathbf k\mathbf i=\mathbf j, $

with reversed products changing sign.

A quaternion is displayed scalar first:

$\displaystyle q = q_w+q_x\mathbf i+q_y\mathbf j+q_z\mathbf k \quad\longleftrightarrow\quad \begin{bmatrix} q_w\ q_x\ q_y\ q_z \end{bmatrix}.$ (6)

For a positive frame rotation through angle $\theta$ about unit axis $\widehat{\mathbf u}$, the passive quaternion is

$\displaystyle {}^{B}q_A = \cos\frac{\theta}{2} - \widehat{\mathbf u}\sin\frac{\theta}{2}.$ (7)

The reverse frame quaternion is

$\displaystyle {}^{A}q_B = ({}^{B}q_A)^*.$ (8)

The corresponding DCMs satisfy

$\displaystyle {}^{A}C_B = ({}^{B}C_A)^T.$ (9)

These equations define the signs used throughout the article.

Definition of a direction cosine matrix

Let

$\displaystyle \left\{ \widehat{\mathbf e}_1^A, \widehat{\mathbf e}_2^A, \widehat{\mathbf e}_3^A \right\} $

and

$\displaystyle \left\{ \widehat{\mathbf e}_1^B, \widehat{\mathbf e}_2^B, \widehat{\mathbf e}_3^B \right\} $

be right handed orthonormal bases.

The passive direction cosine matrix that maps $A$ coordinates into $B$ coordinates has entries

$\displaystyle \left[ {}^{B}C_A \right]_{ij} = \widehat{\mathbf e}_i^B \cdot \widehat{\mathbf e}_j^A.$ (10)

Each entry is therefore the cosine of the angle between one $B$ basis vector and one $A$ basis vector.

The matrix maps coordinate columns according to

$\displaystyle {}^{B}\mathbf v = {}^{B}C_A\,{}^{A}\mathbf v. $

Because both bases are orthonormal,

$\displaystyle ({}^{B}C_A)^T {}^{B}C_A = I,$ (11)

and a proper frame orientation also satisfies

$\displaystyle \det({}^{B}C_A)=+1.$ (12)

Thus

$\displaystyle {}^{B}C_A\in SO(3). $

Quaternion sandwich in vector form

Write a unit quaternion as

$\displaystyle q=q_w+\mathbf q, $

where

$\displaystyle \mathbf q = \begin{bmatrix} q_x\\ q_y\\ q_z \end{bmatrix}. $

For a pure vector quaternion $v=(0,\mathbf v)$, the Hamilton sandwich can be written

$\displaystyle \mathbf v' = \mathbf v + 2q_w(\mathbf q\times\mathbf v) + 2\mathbf q\times (\mathbf q\times\mathbf v).$ (13)

Use the Vector Triple Product identity

$\displaystyle \mathbf q\times (\mathbf q\times\mathbf v) = \mathbf q (\mathbf q\cdot\mathbf v) - (\mathbf q\cdot\mathbf q)\mathbf v. $

Then

\begin{equation*} \begin{aligned} \mathbf v' ={}& \mathbf v + 2q_w(\mathbf q\tim... ...ot\mathbf v) - 2(\mathbf q\cdot\mathbf q)\mathbf v. \end{aligned}\end{equation*}

Since $q$ is unit,

$\displaystyle q_w^2+\mathbf q\cdot\mathbf q=1. $

Therefore

$\displaystyle \mathbf v' = \left( q_w^2-\mathbf q\cdot\mathbf q \right)\mathbf v + 2\mathbf q (\mathbf q\cdot\mathbf v) + 2q_w (\mathbf q\times\mathbf v).$ (14)

Equation (15) is linear in $\mathbf v$, so it can be represented by a $3\times3$ matrix.

Cross product matrix

Define

$\displaystyle [\mathbf q]_{\times} = \begin{bmatrix} 0&-q_z&q_y\ q_z&0&-q_x\ -q_y&q_x&0 \end{bmatrix},$ (15)

so that

$\displaystyle [\mathbf q]_{\times}\mathbf v = \mathbf q\times\mathbf v.$ (16)

Also,

$\displaystyle \mathbf q (\mathbf q\cdot\mathbf v) = \mathbf q\mathbf q^T\mathbf v. $

Therefore equation (15) becomes

$\displaystyle \mathbf v' = \left[ \left( q_w^2-\mathbf q^T\mathbf q \right)I + 2\mathbf q\mathbf q^T + 2q_w[\mathbf q]_{\times} \right] \mathbf v.$ (17)

Hence the quaternion generated matrix is

$\displaystyle C(q) = \left( q_w^2-\mathbf q^T\mathbf q \right)I + 2\mathbf q\mathbf q^T + 2q_w[\mathbf q]_{\times}.$ (18)

For the canonical passive frame quaternion,

$\displaystyle q={}^Bq_A, $

this matrix is exactly ${}^{B}C_A$.

Explicit quaternion to DCM formula

Let

$\displaystyle q = q_w+q_x\mathbf i+q_y\mathbf j+q_z\mathbf k. $

Expanding equation (19) gives

$\displaystyle C(q) = \begin{bmatrix} q_w^2+q_x^2-q_y^2-q_z^2 & 2(q_xq_y-q_wq_z)... ... 2(q_xq_z-q_wq_y) & 2(q_yq_z+q_wq_x) & q_w^2-q_x^2-q_y^2+q_z^2 \end{bmatrix}.$ (19)

Using unit norm, the diagonal terms may also be written

$\displaystyle C(q) = \begin{bmatrix} 1-2(q_y^2+q_z^2) & 2(q_xq_y-q_wq_z) & 2(q_... ...wq_x) \ 2(q_xq_z-q_wq_y) & 2(q_yq_z+q_wq_x) & 1-2(q_x^2+q_y^2) \end{bmatrix}.$ (20)

Equations (20) and (21) are algebraically identical for unit quaternions.

Passive axis angle matrix

For a positive frame rotation,

$\displaystyle q_w=\cos\frac{\theta}{2} $

and

$\displaystyle \mathbf q = -\widehat{\mathbf u} \sin\frac{\theta}{2}. $

Substitute these into equation (19).

Using

$\displaystyle q_w^2-\mathbf q^T\mathbf q = \cos\theta, $

$\displaystyle 2\mathbf q\mathbf q^T = (1-\cos\theta) \widehat{\mathbf u}\widehat{\mathbf u}^T, $

and

$\displaystyle 2q_w[\mathbf q]_{\times} = -\sin\theta [\widehat{\mathbf u}]_{\times}, $

we obtain

$\displaystyle {}^{B}C_A = I\cos\theta + (1-\cos\theta) \widehat{\mathbf u}\widehat{\mathbf u}^T - [\widehat{\mathbf u}]_{\times}\sin\theta.$ (21)

This is the passive Rodrigues matrix.

The negative sine term is expected because the frame rotates positively while the coordinates of a fixed physical vector rotate in the inverse sense.

Check: positive $90^\circ$ frame rotation about $+z$

For

$\displaystyle \theta=90^\circ, \qquad \widehat{\mathbf u}=\widehat{\mathbf z}, $

the passive quaternion is

$\displaystyle {}^{B}q_A = \frac{\sqrt2}{2} - \frac{\sqrt2}{2}\mathbf k.$ (22)

Thus

$\displaystyle q_w=\frac{\sqrt2}{2}, \qquad q_x=q_y=0, \qquad q_z=-\frac{\sqrt2}{2}. $

Equation (21) gives

$\displaystyle {}^{B}C_A = \begin{bmatrix} 0&1&0\ -1&0&0\ 0&0&1 \end{bmatrix}.$ (23)

Apply it to the fixed vector with $A$ coordinates

$\displaystyle {}^{A}\mathbf v = \begin{bmatrix} 1\\ 0\\ 0 \end{bmatrix}. $

Then

$\displaystyle {}^{B}\mathbf v = {}^{B}C_A {}^{A}\mathbf v = \begin{bmatrix} 0\\ -1\\ 0 \end{bmatrix}.$ (24)

This agrees with the quaternion sandwich developed in the preceding PhysicsLibrary article.

What the columns mean

Because

$\displaystyle {}^{B}\mathbf v = {}^{B}C_A\,{}^{A}\mathbf v, $

the columns of ${}^{B}C_A$ have an immediate geometric interpretation.

Let the standard basis columns in frame $A$ be

$\displaystyle {}^{A}\mathbf e_1 = \begin{bmatrix} 1\\ 0\\ 0 \end{bmatrix}, \qqu... ...{bmatrix}, \qquad {}^{A}\mathbf e_3 = \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix}. $

Applying the passive coordinate transformation gives

$\displaystyle {}^{B}C_A = \begin{bmatrix} {}^{B}\mathbf e_1 & {}^{B}\mathbf e_2 & {}^{B}\mathbf e_3 \end{bmatrix}.$ (25)

Thus:

  • the first column is the $B$ coordinate representation of the $A$ frame $x$ basis direction;
  • the second column is the $B$ coordinate representation of the $A$ frame $y$ basis direction;
  • the third column is the $B$ coordinate representation of the $A$ frame $z$ basis direction.

For example,

$\displaystyle {}^{B}\mathbf e_1 = {}^{B}C_A \begin{bmatrix} 1\\ 0\\ 0 \end{bmatrix}$

is simply the first column of ${}^{B}C_A$.

The following illustration shows this column interpretation for a representative unit quaternion and its passive direction cosine matrix.

Image Q09_quaternion_dcm_geometry

Figure. A unit quaternion and its passive direction cosine matrix. The original $A$ frame basis directions are shown together with their coordinate representations in frame $B$. The three columns of ${}^{B}C_A$ are ${}^{B}\mathbf e_1$, ${}^{B}\mathbf e_2$, and ${}^{B}\mathbf e_3$.

This interpretation is also a useful convention check. For the positive $90^\circ$ passive frame rotation about $+z$,

$\displaystyle {}^{B}C_A = \begin{bmatrix} 0&1&0\ -1&0&0\ 0&0&1 \end{bmatrix}. $

Its first column is

$\displaystyle \begin{bmatrix} 0\\ -1\\ 0 \end{bmatrix}, $

which agrees with the passive coordinate result

$\displaystyle {}^{A}\widehat{\mathbf x} \longrightarrow {}^{B}(-\widehat{\mathbf y}). $

Conjugate and transpose

The quaternion conjugate reverses the frame map:

$\displaystyle {}^{A}q_B = ({}^{B}q_A)^*. $

The corresponding matrix relation is

$\displaystyle C(q^*) = C(q)^T.$ (26)

Therefore

$\displaystyle {}^{A}C_B = C({}^{A}q_B) = C(({}^{B}q_A)^*) = ({}^{B}C_A)^T.$ (27)

Since a proper DCM is orthogonal,

$\displaystyle ({}^{B}C_A)^{-1} = ({}^{B}C_A)^T = {}^{A}C_B.$ (28)

Thus quaternion conjugation, quaternion inversion, matrix transposition, and matrix inversion all describe the same reversal of a unit frame transformation.

Quaternion and DCM composition

Suppose

$\displaystyle {}^{B}q_A $

maps $A$ coordinates into $B$ coordinates, and

$\displaystyle {}^{C}q_B $

maps $B$ coordinates into $C$ coordinates.

The quaternion chain is

$\displaystyle {}^{C}q_A = {}^{C}q_B\,{}^{B}q_A. $

Apply the quaternion to matrix map:

$\displaystyle C({}^{C}q_A) = C({}^{C}q_B\,{}^{B}q_A). $

Equation (19) is chosen so that Hamilton multiplication is homomorphic:

$\displaystyle C(pq) = C(p)C(q).$ (29)

Therefore

\begin{equation*} \begin{aligned} {}^{C}C_A &= C({}^{C}q_A)\ &= C({}^{C}q_B) C({}^{B}q_A)\ &= {}^{C}C_B {}^{B}C_A. \end{aligned}\end{equation*}

Hence

$\displaystyle {}^{C}C_A = {}^{C}C_B\,{}^{B}C_A.$ (30)

The quaternion and DCM frame chains have identical written order.

Why some sources show the transpose formula

A different source may use the same Hamilton quaternion coefficients but assign the quaternion to the opposite frame map or to an active vector rotation.

For the same positive geometric rotation, the active rotor is

$\displaystyle q_{\mathrm{active}} = ({}^{B}q_A)^*. $

Its active rotation matrix is

$\displaystyle R_{\mathrm{active}} = C(({}^{B}q_A)^*) = ({}^{B}C_A)^T.$ (31)

Therefore two sources may display matrix formulas that are transposes of one another while describing the same physical orientation from inverse viewpoints.

A quaternion to DCM formula should never be copied without its frame direction and sandwich convention.

The $q$ versus $-q$ ambiguity

The matrices generated by $q$ and $-q$ are identical.

Every term in equations (20) and (21) is quadratic in the quaternion components. Replacing

$\displaystyle q_w,q_x,q_y,q_z $

by their negatives leaves every matrix entry unchanged.

Therefore

$\displaystyle C(-q)=C(q).$ (32)

The map from unit quaternions to proper rotation matrices is two to one.

This is not a numerical defect. It is an intrinsic property of the quaternion representation of three dimensional orientation.

Recovering a quaternion from a DCM

Let

$\displaystyle C = \begin{bmatrix} C_{11}&C_{12}&C_{13}\ C_{21}&C_{22}&C_{23}\ C_{31}&C_{32}&C_{33} \end{bmatrix}$

be a proper DCM that obeys the PhysicsLibrary passive mapping convention.

From equation (20),

$\displaystyle \operatorname{tr}(C) = 4q_w^2-1. $

Therefore

$\displaystyle q_w^2 = \frac{ 1+C_{11}+C_{22}+C_{33} }{4}.$ (33)

When $q_w$ is safely away from zero, select one quaternion sign and compute

$\displaystyle q_w = \frac12 \sqrt{ 1+C_{11}+C_{22}+C_{33} }.$ (34)

The off diagonal differences give

$\displaystyle q_x = \frac{ C_{32}-C_{23} }{ 4q_w },$ (35)
$\displaystyle q_y = \frac{ C_{13}-C_{31} }{ 4q_w },$ (36)
$\displaystyle q_z = \frac{ C_{21}-C_{12} }{ 4q_w }.$ (37)

These signs are consistent with the PhysicsLibrary passive DCM formula in equation (20).

Why the simple trace formula can become ill conditioned

For a frame rotation near $180^\circ$,

$\displaystyle q_w = \cos\frac{\theta}{2} $

is near zero.

The formulas in equations (36) through (38) then divide by a small number. The mathematics remains valid, but the numerical calculation becomes poorly conditioned.

A robust implementation instead chooses the quaternion component associated with the largest diagonal expression.

Robust DCM to quaternion algorithm

Let

$\displaystyle t=C_{11}+C_{22}+C_{33}. $

If $t>0$, define

$\displaystyle S = 2\sqrt{1+t}.$ (38)

Then

$\displaystyle q_w=\frac{S}{4},$ (39)
$\displaystyle q_x=\frac{C_{32}-C_{23}}{S}, \qquad q_y=\frac{C_{13}-C_{31}}{S}, \qquad q_z=\frac{C_{21}-C_{12}}{S}.$ (40)

If $C_{11}$ is the largest diagonal term, define

$\displaystyle S = 2\sqrt{ 1+C_{11}-C_{22}-C_{33} }.$ (41)

Then

$\displaystyle q_w=\frac{C_{32}-C_{23}}{S}, \qquad q_x=\frac{S}{4},$ (42)
$\displaystyle q_y=\frac{C_{12}+C_{21}}{S}, \qquad q_z=\frac{C_{13}+C_{31}}{S}.$ (43)

If $C_{22}$ is the largest diagonal term, define

$\displaystyle S = 2\sqrt{ 1-C_{11}+C_{22}-C_{33} }.$ (44)

Then

$\displaystyle q_w=\frac{C_{13}-C_{31}}{S}, \qquad q_x=\frac{C_{12}+C_{21}}{S},$ (45)
$\displaystyle q_y=\frac{S}{4}, \qquad q_z=\frac{C_{23}+C_{32}}{S}.$ (46)

Otherwise use the $q_z$ branch:

$\displaystyle S = 2\sqrt{ 1-C_{11}-C_{22}+C_{33} }.$ (47)

Then

$\displaystyle q_w=\frac{C_{21}-C_{12}}{S}, \qquad q_x=\frac{C_{13}+C_{31}}{S},$ (48)
$\displaystyle q_y=\frac{C_{23}+C_{32}}{S}, \qquad q_z=\frac{S}{4}.$ (49)

Each branch returns one member of the equivalent pair $q$ and $-q$.

After extraction, numerical software should normally normalize the quaternion to remove roundoff error.

Round trip example with a nontrivial axis

Consider a positive frame rotation of $60^\circ$ about

$\displaystyle \widehat{\mathbf u} = \frac13 \begin{bmatrix} 1\\ 2\\ 2 \end{bmatrix}. $

The passive quaternion is

$\displaystyle {}^{B}q_A = \frac{\sqrt3}{2} -\frac16\mathbf i -\frac13\mathbf j -\frac13\mathbf k.$ (50)

Substitution into equation (20) gives

$\displaystyle {}^{B}C_A = \begin{bmatrix} \frac59 & \frac19+\frac{\sqrt3}{3} & ... ...ac19+\frac{\sqrt3}{3} & \frac29-\frac{\sqrt3}{6} & \frac{13}{18} \end{bmatrix}.$ (51)

The trace is

$\displaystyle \operatorname{tr}({}^{B}C_A)=2. $

Therefore equation (35) gives

$\displaystyle q_w = \frac12\sqrt{3} = \frac{\sqrt3}{2}. $

The vector components recover as

$\displaystyle q_x=-\frac16, \qquad q_y=-\frac13, \qquad q_z=-\frac13. $

Thus the DCM to quaternion conversion returns the original passive quaternion.

Choosing the opposite overall quaternion sign would produce the same DCM.

Orthogonality check

For a quaternion generated matrix,

$\displaystyle C(q^*)=C(q)^T. $

For unit $q$,

$\displaystyle q^*q=1. $

Using the homomorphism property,

\begin{equation*} \begin{aligned} C(q)^TC(q) &= C(q^*)C(q)\ &= C(q^*q)\ &= C(1)\ &= I. \end{aligned}\end{equation*}

Therefore

$\displaystyle C(q)^TC(q)=I.$ (52)

This gives a compact quaternion proof of DCM orthogonality.

Determinant

An orthogonal matrix has determinant $+1$ or $-1$.

At the identity quaternion,

$\displaystyle q=1, $

we have

$\displaystyle C(1)=I $

and therefore

$\displaystyle \det C(1)=+1. $

Unit quaternions vary continuously, and the determinant of an orthogonal matrix cannot change continuously from $+1$ to $-1$ without passing through zero. An orthogonal matrix never has zero determinant.

Therefore every unit quaternion generates a proper rotation matrix:

$\displaystyle \det C(q)=+1.$ (53)

Checking whether a measured matrix is a valid DCM

A numerical matrix intended to represent orientation should satisfy

$\displaystyle C^TC\approx I$ (54)

and

$\displaystyle \det C\approx+1.$ (55)

Measured or numerically propagated matrices may drift slightly away from these conditions.

Converting a badly nonorthogonal matrix directly to a quaternion can produce misleading results. If the deviation is more than roundoff level, the matrix should first be examined or projected back onto $SO(3)$ using a suitable orthogonalization method.

The quaternion extraction formulas assume that the input is already a proper rotation matrix.

Numerical round trip checks

For software validation, perform both conversion directions.

Starting with a normalized quaternion $q$:

  1. compute

    $\displaystyle C=C(q); $
  2. recover

    $\displaystyle \widehat q=C^{-1}_{\mathrm{quat}}(C); $
  3. compare orientation rather than raw component sign.

Because $q$ and $-q$ represent the same orientation, a useful scalar check is

$\displaystyle \left\vert q^T\widehat q \right\vert \approx1.$ (56)

Alternatively compare

$\displaystyle C(q) $

with

$\displaystyle C(\widehat q). $

Starting with a DCM $C$, perform the reverse round trip

$\displaystyle C \longrightarrow q \longrightarrow C(q) $

and verify that the matrices agree to numerical tolerance.

Implementation sign diagnostic

The positive $90^\circ$ frame rotation about $+z$ provides a compact convention test.

PhysicsLibrary expects

$\displaystyle {}^{B}q_A = \begin{bmatrix} \sqrt2/2\ 0\ 0\ -\sqrt2/2 \end{bmatrix}$ (57)

and

$\displaystyle {}^{B}C_A = \begin{bmatrix} 0&1&0\ -1&0&0\ 0&0&1 \end{bmatrix}.$ (58)

Therefore

$\displaystyle \begin{bmatrix} 1\\ 0\\ 0 \end{bmatrix}_{A} \longrightarrow \begin{bmatrix} 0\\ -1\\ 0 \end{bmatrix}_{B}.$ (59)

If a library instead produces

$\displaystyle \begin{bmatrix} 0&-1&0\ 1&0&0\ 0&0&1 \end{bmatrix}, $

it is producing the inverse matrix for this declared passive frame transformation, or equivalently the positive active rotation matrix.

This one case detects many transpose and sign mistakes immediately.

Common pitfalls

  1. Copying a quaternion to DCM formula without its frame direction.

    Two valid formulas may be transposes of one another because they represent inverse maps.

  2. Using an active quaternion with the passive matrix formula without conjugating it.

    For the same positive physical geometry, the active rotor is the conjugate of the canonical passive frame quaternion.

  3. Changing Hamilton multiplication to make matrix composition work.

    PhysicsLibrary keeps Hamilton multiplication and uses the quaternion to DCM assignment in equation (19), for which

    $\displaystyle C(pq)=C(p)C(q). $
  4. Assuming $q$ and $-q$ should produce different matrices.

    They must produce exactly the same DCM.

  5. Using the trace extraction formula near $180^\circ$.

    When $q_w$ is small, use the largest component branch instead.

  6. Forgetting to normalize an extracted quaternion.

    Small floating point errors can move the result slightly away from unit norm.

  7. Extracting a quaternion from a matrix that is not close to $SO(3)$.

    The conversion formulas assume an orthogonal matrix with determinant $+1$.

  8. Comparing round trip quaternion components without accounting for sign.

    A recovered quaternion may equal $-q$ and still represent the identical orientation.

  9. Inferring semantic convention from scalar first or scalar last storage.

    Array layout does not determine frame direction, active or passive meaning, or the multiplication law.

Relationship to adjacent PhysicsLibrary entries

The preceding article, composition of rotations and quaternion order, establishes the passive frame chain

$\displaystyle {}^{C}q_A = {}^{C}q_B\,{}^{B}q_A. $

The present article derives the matrix representation whose frame chain uses the same written order.

A separate companion entry, Quaternions and Direction Cosine Matrices: Examples, Exercises, and Solutions, provides the Q09E self study problem bank.

The next main article, quaternions and Euler angles, uses the quaternion and DCM formulas developed here to derive the intrinsic $3$-$2$-$1$ yaw, pitch, roll conversion under the same passive convention.

Sources and convention notes

The quaternion to matrix relation follows directly from the Hamilton sandwich product. The principal engineering difficulty is convention management: different sources may use inverse frame maps, active vector rotations, transposed DCMs, scalar last storage, or flipped quaternion multiplication.

Sommer and coauthors provide a modern discussion of the Hamilton and flipped multiplication conventions and explain how quaternion to matrix assignments interact with passive frame mappings. Moore provides an openly licensed engineering treatment of reference frames and direction cosine matrices. Henderson's Shuttle era memorandum is a useful historical engineering reference for explicit relationships among Euler Angles, quaternions, and transformation matrices.

Bibliography

1
H. Sommer, I. Gilitschenski, M. Bloesch, S. Weiss, R. Siegwart, and J. Nieto, “Why and How to Avoid the Flipped Quaternion Multiplication,” Aerospace, vol. 5, no. 3, article 72, 2018. Published under CC BY 4.0. Publisher article https://www.mdpi.com/2226-4310/5/3/72
2
J. K. Moore, Learn Multibody Dynamics, chapter “Orientation of Reference Frames.” Distributed under CC BY 4.0. Learn Multibody Dynamics https://moorepants.github.io/learn-multibody-dynamics/orientation.html
3
D. M. Henderson, Euler Angles, Quaternions, and Transformation Matrices: Working Relationships, JSC-12960, NASA Johnson Space Center, Mission Planning and Analysis Division, 1977. Engineering reference. NASA Technical Reports Server search https://ntrs.nasa.gov/search?q=JSC-12960
4
W. R. Hamilton, Elements of Quaternions, 2nd ed., edited by C. J. Joly, Longmans, Green, and Co., 1899. Public domain historical source. Internet Archive scan https://archive.org/details/elementsofquater01hamiuoft

License

Unless otherwise noted, this PhysicsLibrary entry is intended for release under the Creative Commons Attribution ShareAlike 4.0 International license.



"quaternions and direction cosine matrices" is owned by bloftin.
(view preamble)
View style:
See Also: quaternion series overview and article guide, Notation Quaternions for Physics and Engineering: Orientation, quaternion definition and basic algebra, example of quaternion definition and basic algebra, quaternion product, example of quaternion product, quaternion conjugate, example of quaternion conjugate, quaternion norm, example of quaternion norm, quaternion inverse, example of quaternion inverse

Keywords:  quaternion, direction cosine matrix, DCM, rotation matrix, active rotation, passive rotation, frame transformation, attitude matrix

Attachments:
example of quaternions and direction cosine matrices (Example) by bloftin

Cross-references: Euler Angles, reference frames, quaternion multiplication, quaternions and Euler angles, composition of rotations and quaternion order, work, detects, determinant, trace, formulas, conjugation, relation, quaternion conjugate, norm, identity, Vector Triple Product, vector, scalar, matrix, composition, representations, direction cosine matrix, quaternion
There are 4 references to this object.

This is version 3 of quaternions and direction cosine matrices, born on 2026-08-24, modified 2026-08-27.
Object id is 1101, canonical name is QuaternionsAndDirectionCosineMatrices.
Accessed 94 times total.

Classification:
Physics Classification02.40.Yy (Geometric mechanics )
 02.10.Hh (Rings and algebras)
 45.40.-f (Dynamics and kinematics of rigid bodies)
Pending Errata and Addenda
None.
Discussion
Style: Expand: Order:

No messages.

Interact
rate | post | correct | update request | add example | add (any)