A quaternion is a way to represent a rotation in 3 dimensions.
Quaternions have many advantages over other representations like yaw, pitch, roll, for example they can be made unique^[1] and they aren’t subject to [gimbal lock](https://en.wikipedia.org/wiki/Gimbal_lock)^[2].
Quaternions represent rotations using an [axis and an angle](https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representation). They are composed of 4 numbers: usually named X, Y, Z and W. X, Y and Z represent the axis (as a 3D vector), and W is `cos(angle / 2)`.
**[edit]** Quaternion have a “double cover”. They reset after 720°, not 360°. This can make them tricky to use in some situations^[3] (since orientations that appear close can be more than 360° apart).
*************
[1] Which means that every rotation is represented by exactly one quaternion.
[2] Gimbal lock happens when you lose one one degree of freedom due to your orientation. For example, when using yaw pitch and roll, if you pitch up to 90° yaw and roll becomes the same thing which makes everything harder.
[3] [This is what can happens if you aren’t careful when dealing with double cover.](https://www.youtube.com/watch?v=2UEzhenX8IM)
Latest Answers