Trigonometry
Trigonometry and 3D Rotations
Quaternions are an extension of complex numbers for 3D rotations. Used in every 3D engine (Unity, Unreal, ROS for robotics), every smartphone camera, in satellite navigation. Apollo 13 nearly got lost in space due to gimbal lock - a problem quaternions solve elegantly.
- Unity and Unreal Engine: Quaternion.Slerp for smooth character animation without jitter
- ROS (Robot Operating System): tf2 uses quaternions for all coordinate frame transforms
- IMU sensors: gyroscope in smartphone outputs angular velocity, AHRS integrates it into a quaternion
- SLAM (Simultaneous Localization and Mapping): robot pose = position + quaternion orientation
Предварительные знания
SO(3) Rotation Matrices: Geometry of Transformations
Quaternions are used in every 3D engine: Unity, Unreal, ROS for robotics. They are an extension of complex numbers for 3D rotations, discovered by Hamilton in 1843. To understand quaternions, one must first understand what they solve - the gimbal lock problem in rotation matrices.
**Group SO(3)** - all 3D rotation matrices: R in SO(3) if and only if Rᵀ·R = I and det(R) = +1 **Basic rotations around coordinate axes:** Rx(α) = [[1,0,0],[0,cos α,-sin α],[0,sin α,cos α]] Ry(β) = [[cos β,0,sin β],[0,1,0],[-sin β,0,cos β]] Rz(γ) = [[cos γ,-sin γ,0],[sin γ,cos γ,0],[0,0,1]] **Rodrigues formula:** R = I + sin(θ)K + (1-cos θ)K² where K is the skew-symmetric matrix of rotation axis n̂.
Matrix R1 = Rz(90°) @ Rx(30°). Matrix R2 = Rx(30°) @ Rz(90°). Are R1 and R2 the same rotation?
SO(3) is a non-commutative group. To verify: apply R1 to [1,0,0] - first rotate 30° around X, then 90° around Z. Apply R2 to [1,0,0] - first rotate 90° around Z, then 30° around X. The results differ. This non-commutativity is why the order of Euler angle rotations matters critically in aerospace and robotics.
Euler Angles and Gimbal Lock: Why NASA Lost Spacecraft
Apollo 13 nearly got lost in space due to gimbal lock in the inertial navigation system. Euler angles (yaw/pitch/roll) are intuitive, but at pitch = 90 degrees one degree of freedom is lost - two rings of the gyroscope align into one plane.
**ZYX convention (aerospace):** R = Rz(ψ) · Ry(θ) · Rx(φ) ψ - yaw (around Z) θ - pitch (around Y) φ - roll (around X) **Gimbal lock at θ = 90 deg:** Ry(90 deg) = [[0,0,1],[0,1,0],[-1,0,0]] At this value, Rz(ψ)·Ry(90 deg)·Rx(φ) depends only on (ψ - φ), not on ψ and φ separately. One degree of freedom is lost.
Gimbal lock occurs at pitch = 90°. What mathematically explains the loss of one degree of freedom?
At θ = 90°, Ry(90°) maps the X-axis to Z and Z-axis to −X. In Rz(ψ)·Ry(90°)·Rx(φ), the yaw Rz and roll Rx now operate in the same plane. The composition depends only on (ψ − φ), not on ψ and φ separately - one degree of freedom is lost. The Jacobian mapping Euler angles to angular velocity drops from rank 3 to rank 2.
Quaternions: 4 Numbers Instead of 9, No Gimbal Lock
Unity, Unreal, Blender - all store orientation as quaternions. Four numbers (w, x, y, z) fully describe a 3D rotation without singular points. Interpolation via SLERP provides smooth animation with constant angular velocity.
**Rotation quaternion** by angle θ around unit axis n̂: q = cos(θ/2) + sin(θ/2)·(nₓi + nᵧj + n_zk) or in (w, x, y, z) form: w = cos(θ/2), (x,y,z) = sin(θ/2)·n̂ **Applying to vector v:** v' = q · (0+v) · q* (via quaternion multiplication) **SLERP** (Spherical Linear intERPolation): slerp(q₁, q₂, t) = q₁·(q₁⁻¹·q₂)^t, t in [0,1] **q and -q describe the same rotation** (double cover of SO(3) by SU(2)).
Why do quaternion q and −q describe the same 3D rotation?
The rotation formula is v' = q·(0+v)·q*. Substituting −q: (−q)·v·(−q)* = (−q)·v·(−q*) = (−1)²·q·v·q* = q·v·q*. The two sign flips cancel. Physically: adding 2π to the rotation angle θ → θ+2π flips cos(θ/2) and sin(θ/2) to their negatives (q → −q) but the rotation R is the same. This is the 2-to-1 map SU(2) → SO(3).
Key Ideas
- SO(3): R in SO(3) iff RᵀR = I and det(R) = +1; rotations are non-commutative
- Rodrigues formula: R = I + sin(θ)K + (1-cos θ)K² - rotation around any axis in one formula
- Gimbal lock at pitch = 90 deg: Rz and Rx act in the same plane, Jacobian rank drops to 2
- Rotation quaternion: q = [cos(θ/2), sin(θ/2)·n̂], |q| = 1; q and -q describe the same rotation
- SLERP: uniform interpolation along geodesic on 3-sphere - standard for animation in game engines
Related Topics
3D rotations unite trigonometry, linear algebra, and complex analysis:
- Spherical Trigonometry — Quaternions live on the 3-sphere S3; SLERP is a geodesic on it
- SVD and Linear Transformations — SO(3) rotation matrices are a special case of orthogonal matrices from SVD