Skip to content
Physical AI
All experiments

IMU orientation viewer

How roll, pitch and yaw define the orientation of an IMU's body frame relative to the world frame, and how the same orientation is written as a rotation matrix, a quaternion and a projected-gravity vector.

Loading simulation…

What it demonstrates

How roll, pitch and yaw define the orientation of an IMU's body frame relative to the world frame, and how the same orientation is written as a rotation matrix, a quaternion and a projected-gravity vector.

How it works

The three sliders are Z-Y-X Euler angles (yaw about world z, then pitch about the new y, then roll about the new x). They are converted to a rotation matrix R = Rz(ψ)·Ry(θ)·Rx(φ) that maps body-frame vectors into the world frame. The columns of R are the body axes expressed in world coordinates, which is exactly how the solid arrows are drawn.

The quaternion is computed from R with Shepperd's method and shown in MuJoCo's [w, x, y, z] order. Projected gravity is Rᵀ·[0, 0, −1], which is minus the bottom row of R. The world uses the robotics convention x forward, y left, z up; the scene rotates it so z points up on screen.

Adjustable parameters

  • Roll φ (−180° to 180°)
  • Pitch θ (−90° to 90°)
  • Yaw ψ (−180° to 180°)
  • Show world axes
  • Show gravity

Known limitations

  • Pure visualization: orientation is set by sliders, not estimated from sensor data.
  • Euler angles have a singularity at pitch ±90° (gimbal lock). Estimators work with quaternions or rotation matrices internally for this reason.

Equations

R=Rz(ψ) Ry(θ) Rx(ϕ),vworld=R vbodyR = R_z(\psi)\,R_y(\theta)\,R_x(\phi), \qquad v_{world} = R\,v_{body}
R⊤R=I,det⁡R=+1R^\top R = I, \qquad \det R = +1
gb=R⊤[00−1]=[sin⁡θ−sin⁡ϕcos⁡θ−cos⁡ϕcos⁡θ]g_b = R^\top \begin{bmatrix}0\\0\\-1\end{bmatrix} = \begin{bmatrix}\sin\theta\\ -\sin\phi\cos\theta\\ -\cos\phi\cos\theta\end{bmatrix}
q=[cos⁡α2, n^ sin⁡α2]q = \big[\cos\tfrac{\alpha}{2},\ \hat n\,\sin\tfrac{\alpha}{2}\big]

Core update rule

// lib/sim/ch04-imu.ts
const R = eulerToMatrix(roll, pitch, yaw);   // Rz · Ry · Rx
const q = matrixToQuat(R);                   // [w, x, y, z]
const g = [-R[2][0], -R[2][1], -R[2][2]];    // Rᵀ · [0, 0, −1]

Explained in Chapter 4: Sensors & Data