Before touching numbers, one reminder in plain words. A DCM is a 3×3 table of numbers that turns one vector into another; a quaternion is 4 numbers (q0,q1,q2,q3) 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.
Half-angle first. Why this step? The quaternion always stores Φ/2 (the sandwich qvq−1 applies the twist twice; halving cancels the doubling). 2Φ=30°.
Fill the four slots. Why? q0=cos30°, and (q1,q2,q3)=e^sin30°. With e^=(0,0,1) only q3 survives:
q0=23≈0.8660,q1=q2=0,q3=21=0.5
Build C(q). Why plug into the Toolbox C(q) above? It is the neutral hub every representation converts through. With q1=q2=0 every term in the Toolbox matrix that carries a q1 or q2 dies, leaving:
C=q02−q32−2q0q302q0q3q02−q32000q02+q32=21−23023210001
Verify:q02−q32=0.75−0.25=0.5=cos60° ✓ and 2q0q3=2(0.866)(0.5)=0.866=sin60° ✓. Norm 0.75+0.25=1 ✓.
Pieces of Rodrigues. Why? The Toolbox formula C=IcosΦ+[e^]×sinΦ+e^e^⊤(1−cosΦ) needs cos120°=−21, sin120°=23, 1−cos120°=23.
Outer product term. Why? e^e^⊤ has every entry 31, times 23 gives 21 everywhere.
Cross-product term[e^]×sin120°. Why this carries the sign? The antisymmetric [e^]× with e^=31(1,1,1) scaled by 23 gives off-diagonal ±21.
Add them. Diagonal: −21+21=0. In our body-from-inertial, column convention the three terms combine to the cyclic permutation that sends z→y→x→z:
C=010001100
Verify:detC=1, C⊤C=I (orthonormal), and trC=0=1+2cos120° ✓ (the trace-angle identity trC=1+2cosΦ).
Pitch first. Why? From the Toolbox, θ=−arcsinC13 (the minus undoes the −sinθ sitting in C13). Here θ=−arcsin0=0 — no gimbal lock, safe to continue.
Yaw with atan2. Why not atan? The Toolbox gives ψ=atan2(C12,C11). Plain arctan(C11C12)=arctan(−0.866−0.5)=arctan(0.577)=30° — wrong quadrant (the two minus signs cancelled inside the ratio). atan2 keeps both signs separately:
ψ=atan2(−0.5,−0.866)=−150°=210°
Both arguments negative ⇒ third quadrant, which arctan (range ±90°) can never reach.
Roll. Why? ϕ=atan2(C23,C33)=atan2(0,1)=0.
Verify:cos210°=−0.866=C11 ✓, sin210°=−0.5=C12 ✓ (for θ=0, row 1 is (cosψ,sinψ,0)).
Axis is undefined — and that's fine. Why? From Φ=0, sin2Φ=0, so e^sin2Φ=0 regardless of e^. Euler's theorem says "there IS an axis" only when there is a turn; a 0° turn has no unique axis. The quaternion sidesteps this — it stores 0 in the vector part and never asks which axis.
See the danger. Why? q0=211+trC=211−1=0. The Toolbox qi=(Cjk−Ckj)/(4q0) divides by zero.
Pick the largest diagonal — using the general leading-component formula. Why? Shepperd's rule: lead with whichever qi is provably biggest to keep the denominator far from zero. The biggest diagonal entry is C33=+1, pointing to q3. Apply the Toolbox formula qi=211+Cii−Cjj−Ckk with (i,j,k)=(3,1,2):
q3=211+C33−C11−C22=211+1+1+1=1
Fill the rest — spelling out the index order. Why? Once we lead with q3, the other slots come from the cyclic triple (i,j,k)=(3,1,2) divided by 4q3. Concretely: q0=(C12−C21)/(4q3), q1=(C31+C13)/(4q3), q2=(C23+C32)/(4q3) (the plus signs appear because q3-led rows use the symmetric off-diagonal pair). Every one of these numerators is 0 here, so q0=q1=q2=0. Thus q=(0,0,0,1).
Verify:C(q) with q=(0,0,0,1) gives diag(q02+q12−q22−q32,…)=diag(−1,−1,1) ✓.
Pitch. Why? θ=−arcsin(C13)=−arcsin(−1)=+90°. Pitch is straight up.
Detect the lock. Why undefined? At θ=90° the Toolbox row 1 is (cθcψ,cθsψ,−sθ)=(0,0,−1), so C11=C12=0 and ψ=atan2(0,0) is undefined. The yaw and roll axes have become parallel — Gimbal Lock.
Collapse to the determined combination. Why is it ϕ−ψ that survives here? Substitute θ=90° (sθ=1) into C21=sϕsθcψ−cϕsψ=sϕcψ−cϕsψ=sin(ϕ−ψ), and C22=sϕsψ+cϕcψ=cos(ϕ−ψ). So at θ=+90° the matrix depends only on the differenceϕ−ψ. Set ϕ=0 by convention, then
−ψ=atan2(C21,C22)=atan2(−0.5,0.866)=−30°⇒ψ=30°,ϕ−ψ=−30°.
Case (b): θ=−90°.
Pitch at the other pole. Why the sign flip? θ=−arcsin(+1)=−90°, so sθ=−1. The row-1 zeros (C11=C12=0) still hold — it is a lock again.
The fused combination is now ϕ+ψ. Why the sum not the difference? Put sθ=−1 into the same entries: C21=−sϕcψ−cϕsψ=−sin(ϕ+ψ) and C22=−sϕsψ+cϕcψ=cos(ϕ+ψ). So at θ=−90° only ϕ+ψ is determined. Set ϕ=0:
atan2(−C21,C22)=atan2(0.5,0.866)=30°⇒ϕ+ψ=30°⇒ψ=30°.
Report the loss (both poles). Why say it out loud? Only one combined number is real: ϕ−ψ at +90°, ϕ+ψ at −90°. 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.
Two elementary quaternions. Why quaternions to compose? Multiplication of quaternions composes rotations cleanly (no 180° ambiguity). Yaw ψ=90° about z: qψ=(cos45°,0,0,sin45°)=(0.7071,0,0,0.7071). Pitch θ=30° about y: qθ=(cos15°,0,sin15°,0)=(0.9659,0,0.2588,0).
Multiply in the right order. Why qψ⊗qθ? For a 3-2-1 chain the total C=RyRz (pitch applied after yaw); the matching quaternion product is q=qψ⊗qθ using the Hamilton product (a0b0−a⋅b,a0b+b0a+a×b).
Compute.
Scalar: 0.7071(0.9659)−0=0.6830.
Vector: 0.7071(0,0.2588,0)+0.9659(0,0,0.7071)+(0,0,0.7071)×(0,0.2588,0). The cross term (0,0,0.7071)×(0,0.2588,0)=(0(0)−0.7071(0.2588),0.7071(0)−0(0),0(0.2588)−0(0))=(−0.1830,0,0).
Sum vector =(−0.1830,0.1830,0.6830).
q≈(0.6830,−0.1830,0.1830,0.6830)
Verify:∥q∥2=0.68302+0.18302+0.18302+0.68302≈1.000 ✓ (composite of unit quaternions is unit).
Recognise the convention mismatch. Why care? Our locked convention (see the definition box) is body-from-inertial with vbody=Cvinertial. An inertial-from-body matrix is its transpose C⊤. Feeding the wrong one reverses every rotation.
Transpose. Why? Ccorrect=C⊤=010−100001.
Extract q. Using the Toolbox q0-branch: tr=1⇒q0=212=0.7071; q3=(C12−C21)/4q0=(−1−1)/(2.828)=−0.7071. So q=(0.7071,0,0,−0.7071) — a −90° yaw, the reverse of the +90° you'd get from the un-transposed matrix.
Verify: un-transposed gave ψ=+90° (Ex 1-style); transposed gives ψ=−90°. Angles are exact negatives ✓; ∥q∥=1 ✓.
Small-angle limit. Why Taylor-expand? For Φ→0, cos2Φ→1 and sin2Φ→2Φ. So q→(1,0,2Φ,0)=(1,0,0.01,0). This is the linearised form used in Quaternion Kinematics & Propagation.
Sanity of the limit. Why does this matter for propagation? Over one integration step the update is nearly q≈(1,21ωdt); matching that keeps the propagator first-order accurate and shows why renormalization is needed (the exact q0=0.99995=1 drifts the norm).
Verify:sin(0.01)=0.00999983 vs approximation 0.01 — relative error ≈1.7×10−5, tiny as claimed ✓. cos(0.01)2+sin(0.01)2=1 ✓.
Recall Self-test: name the cell
Given only trC=−1, which extraction branch do you use? ::: Shepperd's largest-diagonal branch (Cell E) — q0=0, lead with the biggest qi via qi=211+Cii−Cjj−Ckk.
You read yaw and both atan2 arguments are negative — which quadrant? ::: Third (Cell C); plain atan would give a 180°-wrong first-quadrant answer.
At θ=+90° vs θ=−90°, which Euler combination survives? ::: ϕ−ψ at +90°, ϕ+ψ at −90° (Cell F, gimbal lock — both poles).
Do q and −q ever give different DCMs? ::: No — C(q) is quadratic in q (Cell G).