mathematics//linear algebra//rotation//quaternion

A quaternion is a four-component number, one scalar and a three-vector, and a unit quaternion is a compact way of storing a 3D rotation with no singular attitude; it is the standard attitude representation inside drone autopilots, spacecraft and game engines. A rotation by an angle \(\theta\) about a unit axis \(n\) is stored as


A quaternion is a four-component number, one scalar and a three-vector, and a unit quaternion is a compact way of storing a 3D rotation with no singular attitude; it is the standard attitude representation inside drone autopilots, spacecraft and game engines. A rotation by an angle θ\thetaθ about a unit axis nnn is stored as

q=(cos⁡θ2, sin⁡θ2 n),∥q∥=1.q=\left(\cos\tfrac{\theta}{2},\ \sin\tfrac{\theta}{2}\,n\right),\qquad \|q\|=1 .q=(cos2θ​, sin2θ​n),∥q∥=1.

Four numbers for three degrees of freedom, with one constraint: the length must stay 1. Composing two rotations is the quaternion product (16 multiplications against 27 for two 3 × 3 matrices), rotating a vector is a short formula, and integrating gyroscope rates updates qqq smoothly through any attitude, including the vertical pitch where Euler angles suffer gimbal lock. Two quirks come with it. A quaternion and its negative represent the same rotation, so code comparing attitudes must allow for the sign flip; and rounding slowly pulls the length away from 1, which is fixed by renormalizing, far cheaper than re-orthonormalizing a matrix.

Three degrees of freedom stored in four numbers is the reason for error-state filters.

A Kalman filter that treats the four components as free states gets a 4 × 4 attitude covariance that is singular along the unit-length constraint, and its updates push qqq off the unit sphere. Autopilot filters therefore estimate a three-component attitude error around the current quaternion and fold it back in after every update (extended Kalman filter).

PX4's EKF2 and ArduPilot's EKF3 keep attitude as a quaternion among their roughly two dozen states (orientation, velocity, position, gyroscope and accelerometer biases, magnetic field, wind), and the controllers downstream convert it to a rotation matrix or to Euler angles only where a human or a mixer needs them (autopilot).

A quaternion is not more accurate than a rotation matrix; it represents the same rotations. What it buys is fewer numbers, a constraint that is easy to restore, no singularity and smooth interpolation between attitudes (slerp), at the price of being unreadable to a person: logs and ground stations show Euler angles.

Small rotations make the link with the error state concrete: for a small angle, q≈(1,12δθ)q\approx(1,\tfrac12\delta\theta)q≈(1,21​δθ), so the three components of δθ\delta\thetaδθ are the natural small, unconstrained error to estimate (small-angle approximation).