Apex › Storage & databases

How 3D rotation really works (quaternions & slerp)

Euler angles (yaw/pitch/roll) are intuitive but hit gimbal lock — at pitch 90° two axes align and a degree of freedom vanishes. A unit quaternion q = cos(θ/2) + sin(θ/2)·axis is a point on the 4-sphere with no gimbal lock; it rotates a vector by the sandwich v′ = q·v·q⁻¹, and slerp blends two orientations along the shortest great-circle arc at constant angular velocity. Verified in node: quat→matrix == the Rodrigues axis-angle matrix to 1e-15, v′=q·v·q⁻¹ == R·v, slerp stays unit-norm and moves at constant speed. Blend two poses and compare slerp vs Euler lerp.

More in Storage & databases