3.5.1 · D4Guidance, Navigation & Control (GNC)

Exercises — Reference frames — body frame, inertial frame; rotation between them

2,048 words9 min readBack to topic

Throughout we use the elementary -rotation from the parent note: and its cousins about and :

R_y(\theta)=\begin{bmatrix}\cos\theta&0&-\sin\theta\\0&1&0\\\sin\theta&0&\cos\theta\end{bmatrix}$$ > [!definition] Reading these three matrices > Each takes **inertial** components of a vector and returns its **body** components, when the body has been turned by the stated angle about that one axis. The "1" row/column is the axis you spin *around* — components along the spin axis never change, which is your instant sanity check. --- ## Level 1 — Recognition > [!example] L1·Q1 — Which frame speaks? > A rate gyro outputs $\vec\omega=(0.01,\,0,\,-0.03)$ rad/s. A star tracker outputs a star direction $(0,0,1)$. Which reading is naturally in the **body frame** and which in the **inertial frame**? > [!recall]- Solution L1·Q1 > The **gyro is bolted to the vehicle**, so it measures rotation about the vehicle's own axes → its $\vec\omega$ is in the ==body frame==. A **star tracker** reports the direction of a catalogued star, whose direction is fixed relative to the distant stars → that is the ==inertial frame==. The onboard computer's whole job is to convert between the two. > [!example] L1·Q2 — Spot the axis > You are handed the matrix below. Which axis is it a rotation about, and what is the angle? > $$M=\begin{bmatrix}1&0&0\\0&0&1\\0&-1&0\end{bmatrix}$$ > [!recall]- Solution L1·Q2 > The **first row and first column** are $(1,0,0)$: the $x$-component is untouched, so this spins **about $x$** → compare to $R_x(\phi)$. Matching the block $\begin{bmatrix}\cos\phi&\sin\phi\\-\sin\phi&\cos\phi\end{bmatrix}=\begin{bmatrix}0&1\\-1&0\end{bmatrix}$ gives $\cos\phi=0,\ \sin\phi=1\Rightarrow \phi=+90^\circ$. So $M=R_x(90^\circ)$. > [!example] L1·Q3 — True inverse > A rotation matrix $R$ is given. To convert a vector from body back to inertial, what operation do you apply, and why is it cheap? > [!recall]- Solution L1·Q3 > Apply the **transpose**: $\vec v^{\mathcal I}=R^{\mathsf T}\vec v^{\mathcal B}$. Because a rotation matrix is ==orthogonal== ($R^{\mathsf T}R=I$), its inverse *equals* its transpose. Transposing is just swapping rows and columns — no Gaussian elimination, no division, numerically exact. > [!mistake] The L1 trap — "the star tracker sees body coordinates" > **Why it feels right:** the tracker is physically on the spacecraft, so surely its numbers are body numbers. > **The truth:** the sensor *lives* in the body, but it *reports* a catalogued inertial direction (that's the whole point of star catalogues). What is "in the body" is the raw pixel; the *output* is inertial. > **Fix:** ask *"what does the number describe?"* not *"where is the box?"* --- ## Level 2 — Application > [!example] L2·Q1 — Rotate one vector > The body is turned $+90^\circ$ about $z$. An inertial vector $\vec v^{\mathcal I}=(2,0,0)$. Find $\vec v^{\mathcal B}$ and confirm the length is preserved. > [!recall]- Solution L2·Q1 > $$\vec v^{\mathcal B}=R_z(90^\circ)\begin{bmatrix}2\\0\\0\end{bmatrix}=\begin{bmatrix}0&1&0\\-1&0&0\\0&0&1\end{bmatrix}\begin{bmatrix}2\\0\\0\end{bmatrix}=\begin{bmatrix}0\\-2\\0\end{bmatrix}$$ > **What it looks like (figure below):** the arrow itself never moves; the *observer* turned $+90^\circ$, so the inertial $+X$ arrow now points down the body's $-y$. Length: $\sqrt{0^2+(-2)^2+0^2}=2$ ✔. > > ![[deepdives/dd-physics-3.5.01-d4-s01.png]] > [!example] L2·Q2 — Rotate about $y$ > Body turned $\theta=30^\circ$ about $y$. Inertial vector $\vec v^{\mathcal I}=(0,0,1)$. Find $\vec v^{\mathcal B}$. > [!recall]- Solution L2·Q2 > $$\vec v^{\mathcal B}=R_y(30^\circ)\begin{bmatrix}0\\0\\1\end{bmatrix}=\begin{bmatrix}\cos30^\circ&0&-\sin30^\circ\\0&1&0\\\sin30^\circ&0&\cos30^\circ\end{bmatrix}\begin{bmatrix}0\\0\\1\end{bmatrix}=\begin{bmatrix}-\sin30^\circ\\0\\\cos30^\circ\end{bmatrix}=\begin{bmatrix}-0.5\\0\\0.866\end{bmatrix}$$ > The $z$-axis vector tilts *toward $-x$* in body view because the body rolled its nose the other way. $\sqrt{0.25+0.75}=1$ ✔. > [!example] L2·Q3 — On-axis star > Star direction $\hat s^{\mathcal I}=(0,0,1)$; attitude is $R_z(30^\circ)$. Where does the star appear in body coords? > [!recall]- Solution L2·Q3 > $$\hat s^{\mathcal B}=R_z(30^\circ)\begin{bmatrix}0\\0\\1\end{bmatrix}=\begin{bmatrix}0\\0\\1\end{bmatrix}$$ > The star sits **on** the rotation axis, so a $z$-spin leaves it untouched. This is the fastest possible sanity check on any $z$-rotation. > [!mistake] The L2 trap — plugging degrees into $\cos$ without thinking in radians > **Why it feels right:** we *say* "$\cos 30^\circ$" out loud, so we type `cos(30)`. > **The truth:** software trig expects **radians**; `cos(30)` = $\cos(30\text{ rad})\approx0.154$, silently wrong. > **Fix:** convert first, $30^\circ=\pi/6$ rad, or use a `deg` wrapper. On paper, memorise $\cos30^\circ=\tfrac{\sqrt3}{2}\approx0.866$. --- ## Level 3 — Analysis > [!example] L3·Q1 — Prove orthonormal rows > Take $R_z(\theta)$. Show its three rows are mutually perpendicular unit vectors, and hence $R_z^{\mathsf T}R_z=I$. > [!recall]- Solution L3·Q1 > Rows: $r_1=(\cos\theta,\sin\theta,0)$, $r_2=(-\sin\theta,\cos\theta,0)$, $r_3=(0,0,1)$. > - $\|r_1\|^2=\cos^2\theta+\sin^2\theta=1$; same for $r_2$; $\|r_3\|=1$. All **unit**. > - $r_1\cdot r_2=-\cos\theta\sin\theta+\sin\theta\cos\theta+0=0$; $r_1\cdot r_3=0$; $r_2\cdot r_3=0$. All **perpendicular**. > Entry $(i,j)$ of $R_z R_z^{\mathsf T}$ is $r_i\cdot r_j=\delta_{ij}$, so the product is $I$. **Why it matters:** confirms the inverse is the transpose for this building block — and hence for any product of them. > [!example] L3·Q2 — Determinant sign > Compute $\det R_z(\theta)$ and explain what a value of $+1$ (versus $-1$) tells you physically. > [!recall]- Solution L3·Q2 > Expand along the last row: $\det R_z=1\cdot(\cos\theta\cdot\cos\theta-\sin\theta\cdot(-\sin\theta))=\cos^2\theta+\sin^2\theta=1$. > A determinant of $+1$ means a **proper rotation** — it preserves handedness (right-handed stays right-handed). A determinant of $-1$ would mean a **reflection** was sneaked in, flipping the frame's chirality, which no physical rigid rotation can do. > [!example] L3·Q3 — Why body frame isn't inertial > A student writes $\vec F=m\vec a$ directly in the rotating body frame. Name the extra terms Newton's law actually needs there, and why. > [!recall]- Solution L3·Q3 > In a frame rotating at $\vec\omega$, the true acceleration seen inertially differs from body-measured acceleration by fictitious terms: > $$\vec a^{\mathcal I}=\vec a^{\mathcal B}+2\,\vec\omega\times\vec v^{\mathcal B}+\vec\omega\times(\vec\omega\times\vec r)+\dot{\vec\omega}\times\vec r$$ > These are the ==Coriolis==, ==centrifugal==, and Euler (angular-acceleration) terms. They exist because the body frame is *accelerating* (rotating). Only in $\mathcal I$ is $\vec F=m\vec a$ clean. See [[Coriolis and fictitious forces in rotating frames]]. > [!mistake] The L3 trap — "it's a rotation, so of course $\det=1$; skip it" > **Why it feels right:** you were told rotations have $\det=+1$, so checking feels redundant. > **The truth:** a matrix that is orthogonal ($R^{\mathsf T}R=I$) can still have $\det=-1$ — that's a *reflection*, not a rotation. Orthogonality alone is not enough. > **Fix:** always verify **both** $R^{\mathsf T}R=I$ **and** $\det R=+1$ before trusting a matrix as an attitude. --- ## Level 4 — Synthesis > [!example] L4·Q1 — Chain two frames > Inertial→orbit is $R_{\mathcal O\mathcal I}=R_z(90^\circ)$; orbit→body is $R_{\mathcal B\mathcal O}=R_x(90^\circ)$. Build $R_{\mathcal B\mathcal I}$ and map $\vec v^{\mathcal I}=(1,0,0)$ into the body frame. > [!recall]- Solution L4·Q1 > Adjacent subscripts must touch: apply $\mathcal I\to\mathcal O$ first (rightmost), then $\mathcal O\to\mathcal B$: > $$R_{\mathcal B\mathcal I}=R_{\mathcal B\mathcal O}R_{\mathcal O\mathcal I}=R_x(90^\circ)R_z(90^\circ) > =\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}$$ > Then: > $$\vec v^{\mathcal B}=R_{\mathcal B\mathcal I}\begin{bmatrix}1\\0\\0\end{bmatrix}=\begin{bmatrix}0\\0\\1\end{bmatrix}$$ > **Why:** matrix multiplication is *not* commutative — the order encodes "which turn happened first". Get it backwards and you get a different attitude. > [!example] L4·Q2 — Yaw-pitch-roll (3-2-1) at small angles > For the sequence $R_{\mathcal B\mathcal I}=R_x(\phi)R_y(\theta)R_z(\psi)$ with all angles small, show the linearised matrix and evaluate for $\phi=\theta=\psi=0.01$ rad acting on $\vec v^{\mathcal I}=(1,0,0)$. > [!recall]- Solution L4·Q2 > For small $\alpha$: $\cos\alpha\approx1$, $\sin\alpha\approx\alpha$. Keeping first order and dropping products of small angles: > $$R_{\mathcal B\mathcal I}\approx\begin{bmatrix}1&\psi&-\theta\\-\psi&1&\phi\\\theta&-\phi&1\end{bmatrix}$$ > With $\phi=\theta=\psi=0.01$: > $$\vec v^{\mathcal B}\approx\begin{bmatrix}1&0.01&-0.01\\-0.01&1&0.01\\0.01&-0.01&1\end{bmatrix}\begin{bmatrix}1\\0\\0\end{bmatrix}=\begin{bmatrix}1\\-0.01\\0.01\end{bmatrix}$$ > **Why this tool:** small-angle linearisation turns messy trig into a clean skew-symmetric perturbation — the foundation of onboard attitude filters. See [[Euler angles and gimbal lock]]. > [!example] L4·Q3 — Recover the angle from a DCM > You are given > $$R_{\mathcal B\mathcal I}=\begin{bmatrix}0.6&0.8&0\\-0.8&0.6&0\\0&0&1\end{bmatrix}$$ > Identify it as a single-axis rotation and extract the angle. > [!recall]- Solution L4·Q3 > The third row/column is $(0,0,1)$ → pure $z$-rotation. Match $R_z$: $\cos\theta=0.6$, $\sin\theta=0.8$. Both the $\cos$ (top-left) and the placement of $+\sin$ in the $(1,2)$ slot are consistent, so > $$\theta=\operatorname{atan2}(0.8,\,0.6)=53.13^\circ$$ > **Why atan2 and not plain arctan:** $\arctan(0.8/0.6)$ loses the sign information and can't tell $53.13^\circ$ from $233.13^\circ$. `atan2(sin, cos)` reads *both* signs and returns the correct quadrant — exactly the fix the parent note showed for the naive arctan formula. > [!mistake] The L4 trap — multiplying rotations in reading order > **Why it feels right:** we read left-to-right, so "yaw then pitch then roll" feels like it should be typed $R_z R_y R_x$. > **The truth:** the matrix that is *applied first* to the vector sits on the **right**. A 3-2-1 sequence (yaw first) is written $R_x(\phi)R_y(\theta)R_z(\psi)$ — yaw is rightmost. > **Fix:** let subscript cancellation police you: $R_{\mathcal B\mathcal O}R_{\mathcal O\mathcal I}$ — the touching $\mathcal O$'s must be adjacent, forcing the correct order. --- ## Level 5 — Mastery > [!example] L5·Q1 — Every quadrant of atan2 > A DCM's $z$-rotation gives $(\cos\theta,\sin\theta)$ pairs: **(a)** $(0.6,0.8)$, **(b)** $(-0.6,0.8)$, **(c)** $(-0.6,-0.8)$, **(d)** $(0.6,-0.8)$. Give each angle in degrees in $(-180^\circ,180^\circ]$. > [!recall]- Solution L5·Q1 > Using $\theta=\operatorname{atan2}(\sin\theta,\cos\theta)$: > - **(a)** Q1: $\operatorname{atan2}(0.8,0.6)=+53.13^\circ$ > - **(b)** Q2: $\operatorname{atan2}(0.8,-0.6)=+126.87^\circ$ > - **(c)** Q3: $\operatorname{atan2}(-0.8,-0.6)=-126.87^\circ$ > - **(d)** Q4: $\operatorname{atan2}(-0.8,0.6)=-53.13^\circ$ > **What it looks like (figure):** the same *ratio* $|{\sin}/{\cos}|=4/3$ appears in all four, yet the angles are four different corners of the circle. Plain arctan would collapse (a)&(c) together and (b)&(d) together — that's the failure atan2 repairs. > > ![[deepdives/dd-physics-3.5.01-d4-s02.png]] > [!example] L5·Q2 — Degenerate input > Feed the **zero vector** $\vec v^{\mathcal I}=(0,0,0)$ and the **null rotation** $R_z(0^\circ)=I$ into the machinery. What comes out, and why is each a valid boundary case? > [!recall]- Solution L5·Q2 > - Any rotation of the zero vector: $R\,\vec 0=\vec 0$. A zero-length arrow has no direction, so orientation cannot change it — length $0$ preserved trivially. > - The null rotation $R_z(0)=I$ maps every vector to itself: $\vec v^{\mathcal B}=\vec v^{\mathcal I}$. Body and inertial frames coincide. This is the identity element — the "do nothing" attitude, and a floor test every DCM library must pass. > [!example] L5·Q3 — Composition round-trip (mastery) > Prove that converting inertial→body then body→inertial returns the original vector, for **any** attitude $R$. Then verify numerically with $R=R_z(30^\circ)$ and $\vec v^{\mathcal I}=(1,2,3)$. > [!recall]- Solution L5·Q3 > **Proof:** $\vec v^{\mathcal B}=R\vec v^{\mathcal I}$, then $R^{\mathsf T}\vec v^{\mathcal B}=R^{\mathsf T}R\,\vec v^{\mathcal I}=I\,\vec v^{\mathcal I}=\vec v^{\mathcal I}$, using orthogonality $R^{\mathsf T}R=I$. The round-trip is exact — no drift, no numerical inverse. > **Numeric check** with $R_z(30^\circ)$, $\cos30^\circ=0.8660$, $\sin30^\circ=0.5$: > $$\vec v^{\mathcal B}=\begin{bmatrix}0.866&0.5&0\\-0.5&0.866&0\\0&0&1\end{bmatrix}\begin{bmatrix}1\\2\\3\end{bmatrix}=\begin{bmatrix}1.866\\1.232\\3\end{bmatrix}$$ > Applying $R^{\mathsf T}$ returns $(1,2,3)$ ✔. This exactness is *why* attitude filters transpose instead of invert (see [[Quaternions for attitude representation]] for the same trick with $q^{-1}=q^\ast$). > [!mistake] The L5 trap — using $\arctan$ where $\operatorname{atan2}$ is required > **Why it feels right:** the parent formula $\theta=\arctan(A_y/A_x)$ is burned into memory. > **The truth:** $\arctan$ returns only $(-90^\circ,90^\circ)$; it *cannot* reach quadrants II and III, and dividing $A_y/A_x$ destroys the individual signs (a Q2 point and a Q4 point can share the same ratio). > **Fix:** always pass **both** components separately: $\operatorname{atan2}(A_y,A_x)$. It inspects each sign and returns the full $(-180^\circ,180^\circ]$ answer. --- > [!recall]- One-line summary to self-quiz > Rotate a vector into the body ::: $\vec v^{\mathcal B}=R_{\mathcal B\mathcal I}\vec v^{\mathcal I}$ > Reverse it cheaply ::: transpose, because $R^{-1}=R^{\mathsf T}$ > Chain frames ::: $R_{\mathcal C\mathcal I}=R_{\mathcal C\mathcal B}R_{\mathcal B\mathcal I}$, adjacent subscripts cancel > Extract an angle safely ::: $\theta=\operatorname{atan2}(\sin\theta,\cos\theta)$, never plain arctan > [!mnemonic] Carry these into the exam > **"Right one first, transpose to reverse, atan2 for the corner."** --- Parent: [[3.5.01 Reference frames — body frame, inertial frame; rotation between them (Hinglish)|Reference frames]] · Related: [[IMU and gyroscope sensing]] · [[Attitude determination — star trackers]] · [[ECI, ECEF and orbit reference frames]]