3.5.3 · D4Guidance, Navigation & Control (GNC)

Exercises — Direction cosine matrix (DCM) — construction from Euler angles

2,149 words10 min readBack to topic

Throughout, we use the shorthand from the parent: , , angles in degrees unless a radian is written. A DCM turns inertial-frame coordinates into body-frame coordinates . The three elementary rotations are

R_1(\phi)=\begin{bmatrix}1&0&0\\0&c\phi&s\phi\\0&-s\phi&c\phi\end{bmatrix},\quad R_2(\theta)=\begin{bmatrix}c\theta&0&-s\theta\\0&1&0\\ s\theta&0&c\theta\end{bmatrix}.$$ --- ## Level 1 — Recognition ### L1.1 State, in one sentence each, what the entry $C_{23}$ of a DCM equals **physically** and what unit-length property every **row** of $C$ must satisfy. > [!recall]- Solution > **WHAT $C_{23}$ is:** the $(2,3)$ entry is $\hat b_2\cdot\hat n_3=\cos(\theta_{23})$ — the cosine of the angle between **body axis 2** and **inertial axis 3**. It says "how much of inertial axis 3 points along body axis 2." > **Row property:** each row is a unit vector, so $\sum_j C_{ij}^2=1$ for every row $i$. (Rows are the body axes written in inertial coordinates; body axes have length 1.) ### L1.2 Which single elementary matrix — $R_1$, $R_2$, or $R_3$ — has its minus-sign in the **top-right** corner, and which physical rotation axis does it belong to? > [!recall]- Solution > $R_2(\theta)$ has $-s\theta$ in the top-right. It is the rotation about the **2-axis (pitch)**. The rotation plane for axis 2 is the 3–1 plane, and the cyclic order $3\to1$ (rather than $1\to2$) flips where the minus sign lands. ### L1.3 Given $\psi=0,\ \theta=0,\ \phi=0$, write $C_{BN}$. > [!recall]- Solution > Every $\cos=1$, every $\sin=0$, so all three elementary matrices become the identity and their product is > $$C_{BN}=I=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}.$$ > **Why it must be $I$:** zero rotation means body and inertial frames coincide, so coordinates are unchanged. > [!mistake] L1 trap — "cosine of the angle" vs "the angle" > **Wrong feeling:** students read $C_{23}$ and say "it's the angle between body-2 and inertial-3." > **Why it feels right:** we casually *call* the entries "direction cosines," and the word "angle" is right there. > **Fix:** the entry is the **cosine** of that angle, a pure number in $[-1,1]$, never the angle itself. If you ever see a DCM entry equal to $30$ or $\pi/2$, you have made a category error — entries can never exceed $1$ in magnitude. --- ## Level 2 — Application ### L2.1 Compute $C_{BN}$ for a **pure roll** $\phi=90^\circ$ (with $\psi=\theta=0$). Then find the body coordinates of the inertial vector $\mathbf v_N=[0,1,0]^T$. > [!recall]- Solution > With $\psi=\theta=0$, $C_{BN}=R_1(90^\circ)$. Since $\cos90^\circ=0,\ \sin90^\circ=1$: > $$C_{BN}=\begin{bmatrix}1&0&0\\0&0&1\\0&-1&0\end{bmatrix}.$$ > Then > $$\mathbf v_B=C_{BN}\begin{bmatrix}0\\1\\0\end{bmatrix}=\begin{bmatrix}0\\0\\-1\end{bmatrix}.$$ > **WHAT this looks like:** rolling the body $+90^\circ$ about the 1-axis tips the old $\hat n_2$ (inertial "right") down onto the body's $-3$ direction. See figure below. ![[deepdives/dd-physics-3.5.03-d4-s01.png]] ### L2.2 Compute the full 3-2-1 DCM for $\psi=30^\circ,\ \theta=0^\circ,\ \phi=0^\circ$ and confirm it equals $R_3(30^\circ)$. > [!recall]- Solution > With $\theta=\phi=0$, $R_1=R_2=I$, so $C_{BN}=R_3(30^\circ)$. Using $c30^\circ=\tfrac{\sqrt3}{2}\approx0.8660$, $s30^\circ=0.5$: > $$C_{BN}=\begin{bmatrix}0.8660&0.5&0\\-0.5&0.8660&0\\0&0&1\end{bmatrix}.$$ > **Why:** only the yaw is nonzero, so the 3-2-1 chain collapses to a single 3-axis rotation. ### L2.3 For the DCM of L2.2, compute the body coordinates of $\mathbf v_N=[1,0,0]^T$ and interpret the sign of the result. > [!recall]- Solution > $$\mathbf v_B=\begin{bmatrix}0.8660&0.5&0\\-0.5&0.8660&0\\0&0&1\end{bmatrix}\begin{bmatrix}1\\0\\0\end{bmatrix}=\begin{bmatrix}0.8660\\-0.5\\0\end{bmatrix}.$$ > **Interpretation:** the body yawed $+30^\circ$, so the fixed inertial North now appears **behind and to the body's right** — a positive $b_1$ component ($0.866$) and a **negative** $b_2$ component ($-0.5$). The minus sign is the tell that the body turned toward the vector, not away. > [!mistake] L2 trap — rotating the vector instead of the axes > **Wrong feeling:** "Yaw is $+30^\circ$, so I add $30^\circ$ to the vector's angle and get $+0.5$ in the second slot." > **Why it feels right:** we picture the object physically turning, and turning left feels like $+$. > **Fix:** the DCM re-expresses a *fixed* vector in *rotated axes*. Rotating the axes by $+\theta$ is the same as rotating the vector by $-\theta$ — that is exactly why $R_3$ has $-s\theta$ in the **lower**-left, giving the $-0.5$. When in doubt, trust the matrix, then sanity-check the sign against "did the body turn toward or away from the vector." --- ## Level 3 — Analysis ### L3.1 Prove that the DCM in L2.1 satisfies $C^{-1}=C^{T}$ by direct computation, then explain in one sentence why this had to be true without computing. > [!recall]- Solution > $C=\begin{bmatrix}1&0&0\\0&0&1\\0&-1&0\end{bmatrix}$, so $C^{T}=\begin{bmatrix}1&0&0\\0&0&-1\\0&1&0\end{bmatrix}$. > Then > $$CC^{T}=\begin{bmatrix}1&0&0\\0&0&1\\0&-1&0\end{bmatrix}\begin{bmatrix}1&0&0\\0&0&-1\\0&1&0\end{bmatrix}=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}=I.$$ > Since $CC^T=I$, the transpose **is** the inverse. > **Why without computing:** a rotation preserves lengths and angles, so its rows are orthonormal unit vectors $\Rightarrow C^TC=I \Rightarrow C^{-1}=C^T$. Every genuine DCM has this for free. ### L3.2 Compute $\det C$ for the L2.2 matrix and state what a value of $-1$ would have meant physically. > [!recall]- Solution > Expanding along the third row (which is $[0,0,1]$): > $$\det C = 1\cdot\det\begin{bmatrix}0.8660&0.5\\-0.5&0.8660\end{bmatrix}=0.8660^2-(0.5)(-0.5)=0.75+0.25=1.$$ > **What $-1$ would mean:** a **reflection** (a left-handed frame flip) mixed into the rotation. A proper rotation never reflects, so a DCM must have $\det=+1$. A $\det=-1$ result signals a coding sign error or an improper (mirror) transform. ### L3.3 The bottom-left region of the full 3-2-1 matrix is messy, yet $C_{13}=-s\theta$ is clean. Using this, given a measured DCM with $C_{13}=-0.5$, find pitch $\theta$. Then explain why we choose $\arcsin$ here but $\operatorname{atan2}$ for yaw and roll. > [!recall]- Solution > $C_{13}=-s\theta=-0.5\Rightarrow s\theta=0.5\Rightarrow \theta=\arcsin(0.5)=30^\circ$. > **Why $\arcsin$ for pitch:** pitch is *defined* on $[-90^\circ,+90^\circ]$, exactly the range $\arcsin$ returns, so a single entry pins it down with no quadrant ambiguity. > **Why $\operatorname{atan2}$ for yaw/roll:** those angles range over the full $(-180^\circ,180^\circ]$. A lone $\arcsin$ or $\arccos$ can't tell quadrant II from I (they share the same sine). $\operatorname{atan2}(y,x)$ uses the **signs of both** $y$ and $x$ to place the angle in the correct quadrant — the same fix used for $\arctan$ of a 2D vector. > [!mistake] L3 trap — forgetting det can silently hide a bad matrix > **Wrong feeling:** "My matrix has unit-length rows, so it must be a valid rotation." > **Why it feels right:** orthonormal rows are indeed necessary. > **Fix:** orthonormal rows guarantee $CC^T=I$ but NOT $\det=+1$ — a reflection also has orthonormal rows with $\det=-1$. You must check **both** $CC^T=I$ *and* $\det C=+1$ to certify a proper rotation. This is the boundary between $O(3)$ and [[Rotation group SO(3) and orthogonal matrices|SO(3)]]. --- ## Level 4 — Synthesis ### L4.1 Build the full 3-2-1 DCM for $\psi=90^\circ,\ \theta=0^\circ,\ \phi=90^\circ$ two ways — (i) multiply $R_1(90^\circ)R_2(0^\circ)R_3(90^\circ)$, and (ii) plug into the closed-form matrix from the parent — and confirm they agree. > [!recall]- Solution > **(i) By multiplication.** $R_2(0^\circ)=I$, so $C=R_1(90^\circ)R_3(90^\circ)$. > $$R_3(90^\circ)=\begin{bmatrix}0&1&0\\-1&0&0\\0&0&1\end{bmatrix},\quad > R_1(90^\circ)=\begin{bmatrix}1&0&0\\0&0&1\\0&-1&0\end{bmatrix}.$$ > $$C=R_1R_3=\begin{bmatrix}1&0&0\\0&0&1\\0&-1&0\end{bmatrix}\begin{bmatrix}0&1&0\\-1&0&0\\0&0&1\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&0\end{bmatrix}.$$ > **(ii) Closed form.** With $\theta=0$: $c\theta=1,\ s\theta=0$, $c\psi=0,\ s\psi=1$, $c\phi=0,\ s\phi=1$. The parent's entries give: > - Row 1: $[c\theta c\psi,\ c\theta s\psi,\ -s\theta]=[0,1,0]$. > - Row 2: $[s\phi s\theta c\psi - c\phi s\psi,\ s\phi s\theta s\psi + c\phi c\psi,\ s\phi c\theta]=[0-0,\ 0+0,\ 1]=[0,0,1]$. > - Row 3: $[c\phi s\theta c\psi + s\phi s\psi,\ c\phi s\theta s\psi - s\phi c\psi,\ c\phi c\theta]=[0+1,\ 0-0,\ 0]=[1,0,0]$. > $$C=\begin{bmatrix}0&1&0\\0&0&1\\1&0&0\end{bmatrix}.\quad\text{✔ Both agree.}$$ ### L4.2 Take the small-angle form from the parent, $C\approx I-[\boldsymbol\alpha\times]$ with $\boldsymbol\alpha=(\phi,\theta,\psi)$, and evaluate it for $\phi=\theta=\psi=0.01$ rad. Compare its $(1,2)$ entry to the exact 3-2-1 value. > [!recall]- Solution > The skew matrix built from $\boldsymbol\alpha=(\alpha_1,\alpha_2,\alpha_3)=(\phi,\theta,\psi)$ is > $$[\boldsymbol\alpha\times]=\begin{bmatrix}0&-\alpha_3&\alpha_2\\ \alpha_3&0&-\alpha_1\\ -\alpha_2&\alpha_1&0\end{bmatrix},\quad > C\approx\begin{bmatrix}1&\psi&-\theta\\-\psi&1&\phi\\ \theta&-\phi&1\end{bmatrix}.$$ > With all three $=0.01$: the **approximate** $(1,2)$ entry is $\psi=0.01$. > **Exact** $(1,2)$ entry is $c\theta\,s\psi=\cos(0.01)\sin(0.01)=0.99995\times0.0099998\approx0.0099993$. > Difference $\approx7\times10^{-7}$, confirming the linear model is excellent for milliradian errors — the foundation of the [[Kalman filter — linearized attitude error state|linearized error state]]. > [!mistake] L4 trap — assuming rotation order stops mattering > **Wrong feeling:** "L4.2 showed order doesn't matter to first order, so I can multiply $R_1,R_2,R_3$ in any order for real angles too." > **Why it feels right:** the small-angle result genuinely commutes. > **Fix:** commutativity holds **only** to first order (tiny angles). For finite angles $R_1R_2R_3\ne R_3R_2R_1$ in general — matrix multiplication is non-commutative. L4.1 with $90^\circ$ angles would give a *different* matrix if you reversed the order; try it. Order is negotiable only when angles are milliradian-small. --- ## Level 5 — Mastery ### L5.1 A star tracker reports the DCM $$C=\begin{bmatrix}0&1&0\\0&0&1\\1&0&0\end{bmatrix}.$$ Recover the 3-2-1 Euler angles $(\psi,\theta,\phi)$ using $\theta=-\arcsin(C_{13})$, $\psi=\operatorname{atan2}(C_{12},C_{11})$, $\phi=\operatorname{atan2}(C_{23},C_{33})$. Cross-check against L4.1. > [!recall]- Solution > Read the needed entries: $C_{13}=0,\ C_{12}=1,\ C_{11}=0,\ C_{23}=1,\ C_{33}=0$. > - **Pitch:** $\theta=-\arcsin(0)=0^\circ$. > - **Yaw:** $\psi=\operatorname{atan2}(C_{12},C_{11})=\operatorname{atan2}(1,0)=+90^\circ$. > - **Roll:** $\phi=\operatorname{atan2}(C_{23},C_{33})=\operatorname{atan2}(1,0)=+90^\circ$. > So $(\psi,\theta,\phi)=(90^\circ,0^\circ,90^\circ)$ — exactly the input that produced this matrix in L4.1. ✔ > **Why $\operatorname{atan2}(1,0)=90^\circ$:** the argument corresponds to a point on the positive $y$-axis ($x=0,y=1$), whose angle is a clean $+90^\circ$; a bare $\arctan(1/0)$ would blow up, which is precisely why we use $\operatorname{atan2}$. ### L5.2 Set pitch $\theta=90^\circ$ (gimbal lock) with $\psi=40^\circ,\ \phi=0^\circ$. Compute $C_{BN}$, then show that $(\psi,\phi)=(40^\circ,0^\circ)$ and $(\psi',\phi')=(0^\circ,-40^\circ)$ give the **same** matrix — demonstrating lost uniqueness. > [!recall]- Solution > At $\theta=90^\circ$: $c\theta=0,\ s\theta=1$. Plug into the parent's closed form. > **Case A** $(\psi=40^\circ,\phi=0^\circ)$, with $c\phi=1,s\phi=0$: > - Row 1: $[0,\,0,\,-1]$. > - Row 2: $[s\phi\cdot1\cdot c\psi - c\phi s\psi,\ s\phi\cdot1\cdot s\psi + c\phi c\psi,\ 0]=[-s\psi,\ c\psi,\ 0]=[-s40^\circ,\ c40^\circ,\ 0]$. > - Row 3: $[c\phi\cdot1\cdot c\psi + s\phi s\psi,\ c\phi\cdot1\cdot s\psi - s\phi c\psi,\ 0]=[c\psi,\ s\psi,\ 0]=[c40^\circ,\ s40^\circ,\ 0]$. > $$C_A=\begin{bmatrix}0&0&-1\\-s40^\circ&c40^\circ&0\\ c40^\circ&s40^\circ&0\end{bmatrix}.$$ > **Case B** $(\psi'=0^\circ,\phi'=-40^\circ)$, with $c\psi'=1,s\psi'=0$, $c\phi'=c40^\circ,s\phi'=-s40^\circ$: > - Row 1: $[0,0,-1]$. > - Row 2: $[s\phi'\cdot1\cdot1 - 0,\ 0 + c\phi'\cdot1,\ 0]=[s\phi',\ c\phi',\ 0]=[-s40^\circ,\ c40^\circ,\ 0]$. > - Row 3: $[c\phi'\cdot1\cdot1 + 0,\ 0 - s\phi'\cdot1,\ 0]=[c\phi',\ -s\phi',\ 0]=[c40^\circ,\ s40^\circ,\ 0]$. > $$C_B=\begin{bmatrix}0&0&-1\\-s40^\circ&c40^\circ&0\\ c40^\circ&s40^\circ&0\end{bmatrix}=C_A.\ \text{✔}$$ > **What this shows:** at $\theta=90^\circ$ only the **sum** (here $\psi-\phi$ style combination) matters; $\psi$ and $\phi$ trade off freely along one axis. The DCM is perfectly well-defined, but the *angle decomposition* is not — this is [[Quaternions — avoiding gimbal lock|gimbal lock]], and why flight software stores attitude as a quaternion. ![[deepdives/dd-physics-3.5.03-d4-s02.png]] ### L5.3 Using $C=R_1(\phi)R_2(\theta)R_3(\psi)$, prove the composed matrix is orthogonal ($CC^T=I$) **without expanding it**, given each $R_i$ is orthogonal. > [!recall]- Solution > Each elementary matrix is orthogonal: $R_i R_i^T=I$, i.e. $R_i^T=R_i^{-1}$. Then > $$CC^T=(R_1R_2R_3)(R_1R_2R_3)^T=R_1R_2R_3\,R_3^TR_2^TR_1^T.$$ > Peel from the inside: $R_3R_3^T=I$, leaving $R_1R_2R_2^TR_1^T$; then $R_2R_2^T=I$, leaving $R_1R_1^T=I$. > $$CC^T=I.$$ > **Why this is powerful:** a product of rotations is automatically a rotation — the group [[Rotation group SO(3) and orthogonal matrices|SO(3)]] is *closed* under multiplication. You never have to re-verify orthonormality of a composed DCM; it is inherited. > [!mistake] L5 trap — "gimbal lock means the DCM broke" > **Wrong feeling:** "At $\theta=90^\circ$ my angle solver returns garbage, so the DCM is singular/unusable." > **Why it feels right:** the recovery formulas $\operatorname{atan2}(C_{12},C_{11})$ hit $\operatorname{atan2}(0,0)$, which is undefined. > **Fix:** the **matrix** $C$ is a perfectly valid rotation with $\det=+1$ and $CC^T=I$ — nothing broke. It is the *Euler-angle parameterization* that becomes non-unique. Propagate attitude in a non-singular representation (quaternion or DCM directly) and only convert to Euler angles for human display, guarding the $\theta=\pm90^\circ$ case. --- > [!recall]- Feynman recap: what these exercises trained > L1–L2 taught you to *read and plug in* the turn-tables. L3 made you *audit* a matrix ($CC^T=I$ and $\det=+1$ together). L4 built full attitudes two ways and showed order only stops mattering for tiny turns. L5 handed you a matrix and asked "what turns made this?" — and revealed that near a straight-up pitch the answer stops being unique. That last lesson is *the* reason spacecraft carry [[Quaternions — avoiding gimbal lock|quaternions]]. > [!mnemonic] Grading ladder > **"Read, Run, Reason, Rebuild, Rule."** L1 Read the entries · L2 Run the multiplication · L3 Reason about det/inverse · L4 Rebuild the full DCM · L5 Rule over the inverse problem and gimbal lock. ## Connections - [[Direction cosine matrix (DCM) — construction from Euler angles]] - [[Quaternions — avoiding gimbal lock]] - [[Euler angles — kinematic differential equations]] - [[Rotation group SO(3) and orthogonal matrices]] - [[Attitude determination — TRIAD & QUEST]] - [[Kalman filter — linearized attitude error state]] - [[Angular velocity and skew-symmetric matrices]]