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.
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
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