3.5.10 · D3Guidance, Navigation & Control (GNC)

Worked examples — Converting between DCM, quaternions, Euler angles

2,940 words13 min readBack to topic

This page drills the conversions from the parent topic until no case can surprise you. We hit every quadrant, every sign, every degenerate input, and the two exam traps everybody falls into. Prereqs we lean on: Euler's Rotation Theorem, Rodrigues Rotation Formula, Direction Cosine Matrix Properties, Gimbal Lock, Rotation Sequences (3-2-1 vs 3-1-3), Quaternion Kinematics & Propagation.

Before touching numbers, one reminder in plain words. A DCM is a table of numbers that turns one vector into another; a quaternion is 4 numbers that store the axis and half the angle of one twist; Euler angles are three ordinary turn-amounts (roll, pitch, yaw). All three describe the same physical turn.


The scenario matrix

Every conversion problem you can be handed falls into one of these cells. The worked examples below are tagged with the cell they cover.

Cell What makes it tricky Covered by
A. Cardinal axis, small angle clean numbers, learn the machinery Ex 1
B. Off-diagonal signs (which sign of ?) Rodrigues sign bookkeeping Ex 2
C. Quadrant II/III/IV Euler angle atan2 vs atan — the big trap Ex 3
D. Zero rotation (identity) degenerate: axis undefined Ex 4
E. rotation () Shepperd division-by-zero branch Ex 5
F. Gimbal lock () one DOF vanishes — both signs Ex 6
G. Sign ambiguity vs same attitude, two 4-tuples Ex 7
H. Real-world word problem build the rotation from a story Ex 8
I. Exam twist: wrong convention (transpose) reversed rotation Ex 9
J. Composite / limiting behaviour half-angle limit, Ex 10

Example 1 — Cell A: cardinal axis, small clean angle

  1. Half-angle first. Why this step? The quaternion always stores (the sandwich applies the twist twice; halving cancels the doubling). .
  2. Fill the four slots. Why? , and . With only survives:
  3. Build . Why plug into the Toolbox above? It is the neutral hub every representation converts through. With every term in the Toolbox matrix that carries a or dies, leaving:
Figure — Converting between DCM, quaternions, Euler angles

Verify: ✓ and ✓. Norm ✓.


Example 2 — Cell B: off-diagonal signs, tilted axis

  1. Pieces of Rodrigues. Why? The Toolbox formula needs , , .
  2. Outer product term. Why? has every entry , times gives everywhere.
  3. Cross-product term . Why this carries the sign? The antisymmetric with scaled by gives off-diagonal .
  4. Add them. Diagonal: . In our body-from-inertial, column convention the three terms combine to the cyclic permutation that sends :

Verify: , (orthonormal), and ✓ (the trace-angle identity ).


Example 3 — Cell C: quadrant II/III/IV Euler extraction

  1. Pitch first. Why? From the Toolbox, (the minus undoes the sitting in ). Here — no gimbal lock, safe to continue.
  2. Yaw with atan2. Why not atan? The Toolbox gives . Plain wrong quadrant (the two minus signs cancelled inside the ratio). atan2 keeps both signs separately: Both arguments negative ⇒ third quadrant, which (range ) can never reach.
  3. Roll. Why? .
Figure — Converting between DCM, quaternions, Euler angles

Verify: ✓, ✓ (for , row 1 is ).


Example 4 — Cell D: identity / zero rotation (degenerate axis)

  1. Trace branch. Why? .
  2. Vector part. Why zero? Off-diagonal differences , so . Thus .
  3. Axis is undefined — and that's fine. Why? From , , so regardless of . Euler's theorem says "there IS an axis" only when there is a turn; a turn has no unique axis. The quaternion sidesteps this — it stores in the vector part and never asks which axis.
  4. Euler. , , .

Verify: with gives ✓. Norm ✓.


Example 5 — Cell E: rotation, Shepperd branch

  1. See the danger. Why? . The Toolbox divides by zero.
  2. Pick the largest diagonal — using the general leading-component formula. Why? Shepperd's rule: lead with whichever is provably biggest to keep the denominator far from zero. The biggest diagonal entry is , pointing to . Apply the Toolbox formula with :
  3. Fill the rest — spelling out the index order. Why? Once we lead with , the other slots come from the cyclic triple divided by . Concretely: , , (the plus signs appear because -led rows use the symmetric off-diagonal pair). Every one of these numerators is here, so . Thus .

Verify: with gives ✓.


Example 6 — Cell F: gimbal lock at BOTH and

Case (a): .

  1. Pitch. Why? . Pitch is straight up.
  2. Detect the lock. Why undefined? At the Toolbox row 1 is , so and is undefined. The yaw and roll axes have become parallel — Gimbal Lock.
  3. Collapse to the determined combination. Why is it that survives here? Substitute () into , and . So at the matrix depends only on the difference . Set by convention, then

Case (b): .

  1. Pitch at the other pole. Why the sign flip? , so . The row-1 zeros () still hold — it is a lock again.
  2. The fused combination is now . Why the sum not the difference? Put into the same entries: and . So at only is determined. Set :
  3. Report the loss (both poles). Why say it out loud? Only one combined number is real: at , at . Splitting it into a specific and is an arbitrary choice. One DOF of the representation is gone at either pole; the physical attitude is perfectly fine.
Figure — Converting between DCM, quaternions, Euler angles

Verify: (a) : ✓, ✓. (b) : ✓, ✓.


Example 7 — Cell G: vs are the same attitude

  1. Build both. Why? Every entry of the Toolbox is a product of two -components (quadratic). Flipping every sign flips — no change.
  2. Concretely : from it's ; from it's . Identical.
  3. Unique representative. Why enforce ? To pick the "shortest-arc" twist and avoid two names for one attitude in a database.

Verify: entrywise; both equal the -about- matrix of Example 1 ✓.


Example 8 — Cell H: real-world word problem

  1. Two elementary quaternions. Why quaternions to compose? Multiplication of quaternions composes rotations cleanly (no ambiguity). Yaw about : . Pitch about : .
  2. Multiply in the right order. Why ? For a 3-2-1 chain the total (pitch applied after yaw); the matching quaternion product is using the Hamilton product .
  3. Compute. Scalar: . Vector: . The cross term . Sum vector .

Verify: ✓ (composite of unit quaternions is unit).


Example 9 — Cell I: exam twist, the transpose trap

  1. Recognise the convention mismatch. Why care? Our locked convention (see the definition box) is body-from-inertial with . An inertial-from-body matrix is its transpose . Feeding the wrong one reverses every rotation.
  2. Transpose. Why? .
  3. Extract . Using the Toolbox -branch: ; . So — a yaw, the reverse of the you'd get from the un-transposed matrix.

Verify: un-transposed gave (Ex 1-style); transposed gives . Angles are exact negatives ✓; ✓.


Example 10 — Cell J: limiting behaviour, half-angle as

  1. Exact quaternion. , .
  2. Small-angle limit. Why Taylor-expand? For , and . So . This is the linearised form used in Quaternion Kinematics & Propagation.
  3. Sanity of the limit. Why does this matter for propagation? Over one integration step the update is nearly ; matching that keeps the propagator first-order accurate and shows why renormalization is needed (the exact drifts the norm).

Verify: vs approximation — relative error , tiny as claimed ✓. ✓.


Recall Self-test: name the cell

Given only , which extraction branch do you use? ::: Shepperd's largest-diagonal branch (Cell E) — , lead with the biggest via . You read yaw and both atan2 arguments are negative — which quadrant? ::: Third (Cell C); plain atan would give a -wrong first-quadrant answer. At vs , which Euler combination survives? ::: at , at (Cell F, gimbal lock — both poles). Do and ever give different DCMs? ::: No — is quadratic in (Cell G).