Autonomous Vehicle/Video Geometry

[3D Rotation Matrix] Quaternions

Naranjito 2025. 11. 21. 14:45
  • A quaternion q is a 4D number:
\[ q = q_{1}\mathbf{i} + q_{2}\mathbf{j} + q_{3}\mathbf{k} + q_{4} \] Or written as a vector: \[ q = [\, q_{1},\, q_{2},\, q_{3},\, q_{4} \,] \] Where: \[ -\ \mathbf{i},\ \mathbf{j},\ \mathbf{k} \text{ are like imaginary unit vectors (just like how complex numbers have } i\text{)} \] \[ -\ q_{1},\ q_{2},\ q_{3} \text{ form a vector part (representing axis)} \] \[ -\ q_{4} \text{ is a scalar part (related to angle)} \] So a quaternion as: \[ q = [\, \text{axis vector},\ \text{angle scalar} \,] \]

  • A quaternion is a 4D number: 3D axis vector + 1 scalar

  • A super powerful tool to represent 3D rotations, often preferred over Euler angles or rotation matrices because they're more compact, efficient, and don’t suffer from gimbal lock.

  • A unit quaternion has length 1:
\[ |q|^{2} = q_{1}^{2} + q_{2}^{2} + q_{3}^{2} + q_{4}^{2} = 1 \]

  • Relation to Screw Parameters

 

- They describe the same thing-Rotation around an axis by an angle but Just written differently:

\[ \text{Screw: } [\, \theta,\, \hat{w} \,] \] \[ \text{Quaternion: } [\, \sin(\theta/2)\,\hat{w},\ \cos(\theta/2) \,] \]

For example, given :

\[ \text{Axis of rotation: } \hat{w} = [0, 0, 1] \;\rightarrow\; \text{rotation around the Z-axis} \] \[ \text{Angle of rotation: } \theta = 90^\circ = \frac{\pi}{2} \text{ radians} \]

Step 1: Use the quaternion formula

\[ q = [\, \sin(\theta/2)\, w_{1},\ \sin(\theta/2)\, w_{2},\ \sin(\theta/2)\, w_{3},\ \cos(\theta/2) \,] \]

Step 2: Plug in values

\[ \theta = 90^\circ = \frac{\pi}{2} \;\Rightarrow\; \frac{\theta}{2} = \frac{\pi}{4} \] And: \[ \sin\!\left(\frac{\pi}{4}\right) = \frac{\sqrt{2}}{2} \approx 0.7071 \] \[ \cos\!\left(\frac{\pi}{4}\right) = \frac{\sqrt{2}}{2} \approx 0.7071 \] The axis is \[ \hat{w} = [0,0,1]\], so: \[ w_{1} = 0 \] \[ w_{2} = 0 \] \[ w_{3} = 1 \]

Step 3: Compute each component

\[ q_{1} = \sin(\theta/2)\cdot 0 = 0 \] \[ q_{2} = \sin(\theta/2)\cdot 0 = 0 \] \[ q_{3} = \sin(\theta/2)\cdot 1 = 0.7071 \] \[ q_{4} = \cos(\theta/2) = 0.7071 \]

Final Quaternion:

\[ q = [\, 0,\ 0,\ 0.7071,\ 0.7071 \,] \]

Normalize:

\[ \sqrt{0^{2} + 0^{2} + 0.7071^{2} + 0.7071^{2}} = \sqrt{0.5 + 0.5} = 1 \]