← All notes

Rotation Representations

Rotation Representations

Representation Params Pros Cons In this project
Rotation matrix R∈SO(3)R\in SO(3) 9 unique, easy to apply redundant, drifts from orthonormal Vicon ground truth rots
Axis-angle / rotation vector ϕ=θu\boldsymbol\phi = \theta\mathbf u 3 minimal, great for small errors singular-ish at θ = 2π, not composable by addition UKF error state, sigma offsets
Unit quaternion 4 no singularity, cheap composition double cover, 1 constraint UKF state
Euler angles (ZYX) 3 human-readable gimbal lock, order-dependent output roll / pitch / yaw

Rotation matrix

Columns are the body axes expressed in the world frame. RTR=IR^TR = I, det⁡R=1\det R = 1. Inverse = transpose. Body → world: vw=R vb\mathbf v_w = R\,\mathbf v_b.

Axis-angle

Rodrigues' formula, with [u]×[\mathbf u]_\times the skew matrix of u:

R=I+sin⁡θ [u]×+(1−cos⁡θ)[u]×2R = I + \sin\theta\,[\mathbf u]_\times + (1-\cos\theta)[\mathbf u]_\times^2
Going back: θ=arccos⁡tr⁡R−12\theta = \arccos\frac{\operatorname{tr}R - 1}{2}, [u]×=R−RT2sin⁡θ[\mathbf u]_\times = \frac{R-R^T}{2\sin\theta} — undefined at θ = 0 and π, the issue in from_rotm ([[Code Review - Bugs and Fixes#6. from_rotm() divides by sin θ|bug #6]]).

Matrix → quaternion

Robust (Shepperd) method: pick the largest of tr⁡R, R00, R11, R22\operatorname{tr}R,\ R_{00},\ R_{11},\ R_{22} and divide by the square root of that, so you never divide by ~0. If tr⁡R>0\operatorname{tr}R > 0:

w=121+tr⁡R,x=R21−R124w,y=R02−R204w,z=R10−R014ww = \tfrac12\sqrt{1+\operatorname{tr}R},\quad x = \frac{R_{21}-R_{12}}{4w},\quad y = \frac{R_{02}-R_{20}}{4w},\quad z = \frac{R_{10}-R_{01}}{4w}
(ukf_core.rotm_to_quat implements all four branches.)

Euler angles (ZYX)

Yaw ψ about z, then pitch θ about the new y, then roll φ about the new x:

R=Rz(ψ) Ry(θ) Rx(ϕ)R = R_z(\psi)\,R_y(\theta)\,R_x(\phi)
From a quaternion (same as Quaternion.euler_angles and quat_to_euler):
ϕ=atan2⁡(2(wx+yz), 1−2(x2+y2))\phi = \operatorname{atan2}\big(2(wx+yz),\ 1-2(x^2+y^2)\big)
θ=arcsin⁡(2(wy−zx))\theta = \arcsin\big(2(wy-zx)\big)
ψ=atan2⁡(2(wz+xy), 1−2(y2+z2))\psi = \operatorname{atan2}\big(2(wz+xy),\ 1-2(y^2+z^2)\big)
Clip the arcsin argument to [−1, 1].

Gimbal lock

At θ = ±90° the first and last rotation axes line up: roll and yaw rotate about the same physical axis. Only their difference (θ = +90°) or sum (θ = −90°) is defined:

R∣θ=+90°=[0sin⁡(ϕ−ψ)cos⁡(ϕ−ψ)0cos⁡(ϕ−ψ)−sin⁡(ϕ−ψ)−100]R\big|_{\theta=+90°} = \begin{bmatrix}0 & \sin(\phi-\psi) & \cos(\phi-\psi)\\ 0 & \cos(\phi-\psi) & -\sin(\phi-\psi)\\ -1 & 0 & 0\end{bmatrix}

Distance between rotations

The geodesic distance — the angle of the rotation that takes one to the other:

d(q1,q2)=∥log⁡(q1−1⊗q2)∥=2arccos⁡∣⟨q1,q2⟩∣d(q_1, q_2) = \lVert\log(q_1^{-1}\otimes q_2)\rVert = 2\arccos|\langle q_1,q_2\rangle|
The absolute value handles the double cover.

Next: Exponential and Log Maps · back to Quaternions

Connections

Linked from