3.5.10 · D4Guidance, Navigation & Control (GNC)

Exercises — Converting between DCM, quaternions, Euler angles

1,968 words9 min readBack to topic

This is the practice arena for the parent topic. Every problem is graded L1 → L5. Try it first, then open the collapsible solution. All the machinery lives in the parent note: Rodrigues Rotation Formula, Direction Cosine Matrix Properties, Quaternion Kinematics & Propagation, Gimbal Lock, Rotation Sequences (3-2-1 vs 3-1-3).

trace and antisym

read entries

via DCM hub

axis angle e Phi

DCM C

quaternion q

Euler phi theta psi

Before we start, one figure fixes all the conventions and symbols we will reuse.

Figure — Converting between DCM, quaternions, Euler angles

Level 1 — Recognition

L1.1 — Read a quaternion's axis and angle

The quaternion is given. What is the rotation axis and the turn angle ?

Recall Solution — L1.1

WHAT we use: the axis–angle definition and . WHY this and not the DCM: the axis and angle are directly baked into the quaternion; no matrix needed.

From we get , so . The vector part must equal . Dividing by : .

Answer: axis (the -axis), angle .

L1.2 — Recognise the trace shortcut

For any rotation quaternion, the trace of its DCM is . Given , find (taking the positive root).

Recall Solution — L1.2

WHAT/WHY: the parent note proves . This one scalar carries , so it's the fastest handle. Sanity: — matches L1.1's kind of rotation.


Level 2 — Application

L2.1 — Quaternion → DCM (build the matrix)

Convert into its DCM .

Recall Solution — L2.1

WHAT: plug into the parent's formula. WHY: to rotate vectors we need matrix form. Here , so , and .

  • ,
  • all other off-diagonals contain or . This is a pure yaw about (see the parent's Example 1). ✓

L2.2 — Euler → DCM (3-2-1) for a single pitch

Compute , i.e. pure pitch , roll , yaw .

Recall Solution — L2.2

WHAT: substitute into the parent's 3-2-1 matrix with (). WHY: confirms you can read the general formula by killing terms. The middle row/column is untouched because we spin about : the -axis is fixed. That's the geometric "look".

L2.3 — DCM → Euler extraction

From the matrix of L2.2, recover using the parent's extraction rules.

Recall Solution — L2.3

WHAT/WHY: we read specific entries because they isolate one angle each (parent "DCM → Euler").

  • — but here , so , giving ✓ Round trip recovered exactly. (Note: only truly undefined when , i.e. gimbal lock — not here.)

Level 3 — Analysis

L3.1 — DCM → Quaternion, safe branch

Given recover using the trace branch, and enforce .

Recall Solution — L3.1

WHAT: trace first. , so . WHY the trace branch is safe here: is comfortably away from , so dividing by is fine.

  • This is exactly the input of L2.1 — the conversion is a perfect inverse. ✓

L3.2 — DCM → Quaternion, singular branch (near 180°)

For (a rotation about ), the trace branch fails. Recover correctly.

Recall Solution — L3.2

WHAT: . Dividing by is illegal — this is why Shepperd says divide by the largest component. WHY: at the scalar part vanishes; the biggest diagonal tells us which vector component dominates. The diagonal entries are ; the largest is , so solve for : Then the off-diagonals give the rest via , and . Check: ; axis ✓.

L3.3 — Detect and handle gimbal lock

A DCM has . Show that this is gimbal lock, find , and explain what is (and isn't) recoverable.

Recall Solution — L3.3

WHAT: . WHY it's a singularity: with , , so in the parent matrix and . Then is undefined — the yaw and roll axes have aligned (see Gimbal Lock). What survives: the off-diagonal block collapses so that only the sum is determined (for ), not each separately. Convention: set , then is read from — that combined angle is fully valid; the split is a free choice. One degree of freedom is reported as lost.


Level 4 — Synthesis

L4.1 — Full chain: Euler → DCM → quaternion

Take . Build , then extract , and confirm the "via-the-hub" workflow.

Recall Solution — L4.1

WHY via DCM: memorising a direct Euler→quaternion formula (12 terms) is error-prone; compose two trusted maps (parent Example: use the DCM as neutral hub).

Step 1 (Euler→DCM): pure yaw . Using L2.2-style substitution with only : Step 2 (DCM→quaternion): identical to L3.1 → . Cross-check via axis–angle: yaw about , ✓. The hub route and the direct axis–angle route agree.

L4.2 — Compose two rotations, then read the axis

Apply a yaw ( from L4.1) followed by a roll about (). Multiply the quaternions () and report of the combined rotation.

Recall Solution — L4.2

WHAT/WHY: quaternion multiplication composes rotations cheaply (parent: quaternions are best for propagation). Hamilton product with : With , :

  • ,
  • Norm check: ✓. Angle: . The combined turn is about axis .

Level 5 — Mastery

L5.1 — Prove the trace identity

Starting from the parent's , prove that using the unit-norm constraint.

Recall Solution — L5.1

WHAT: add the three diagonal entries. The terms: ; likewise and each net ; nets . So WHY the constraint enters: use :

L5.2 — Round-trip robustness at 180°

Show that for (parent Example 2, about ), rebuilding from the recovered quaternion returns the original matrix — verifying the singular branch is not just a hack.

Recall Solution — L5.2

Step 1 — extract (largest diagonal is ): and , , giving . Step 2 — rebuild via with , rest :

  • ,
  • all off-diagonals contain . The singular branch is exact — it reproduces the matrix bit-for-bit.

L5.3 — Sign ambiguity is physical, not a bug

Show that and produce the same DCM, and state the convention that picks a unique representative.

Recall Solution — L5.3

WHY: the parent notes is quadratic in ; every entry is a product of two components, so flipping all signs leaves every product unchanged. Check the only nonzero-driving term: . Whether or , , so identically; same for . Off-diagonals stay . Both quaternions give . Convention: enforce (and if , fix the sign of the first nonzero vector component). This selects the shortest-arc representative and removes the double cover ambiguity.


Recall One-line self-test before you leave

gives ::: , hence (L1.2, L3.1, L5.1). To apply rotation then you multiply ::: — second rotation on the left (L4.2). Gimbal lock happens at pitch ::: , where only is recoverable (L3.3). Near you divide by ::: the largest quaternion component, not (L3.2, L5.2).