This post is part of my Game Math Series.
A quaternion is a very useful mathematical object devised by Sir William Rowan Hamilton as an extension to complex numbers. It is often used to compactly represent 3D orientations with just four floating-point numbers, as opposed to using a 3-by-3 matrix that contains nine floating-point numbers, and it has other nice properties that I will talk about later.
As its name suggests, a quaternion is composed of four components, one in the real part, and the other three in the imaginary part. A quaternion is usually denoted as:
      ![]()
where 
 is the real part, 
 denotes the three imaginary axes, and 
 denotes the three imaginary components.
For brevity, I will use the notation below to represent a quaternion:
      ![]()
The Fundamental Formula for Quaternions
Below is the fundamental formula that governs the arithmetics of quaternions:
      ![]()
With this formula, we can derive the following identities:
								


![Rendered by QuickLaTeX.com \[ M =  {\left[ {\begin{array}{ccc}    0 & 1 & 1 \\    1 & 2 & 3 \\    0 & 0 & 1 \\   \end{array} } \right]} \]](https://allenchou.net/wp-content/ql-cache/quicklatex.com-6086ea30e24655aebb352d835179c15a_l3.png)
![Rendered by QuickLaTeX.com \[ A =  {\left[ {\begin{array}{cccc}    1 & 1 & 0 & 0 \\    1 & 1 & 0 & 0 \\    0 & 0 & 1 & 1 \\    0 & 0 & 1 & 1 \\   \end{array} } \right]} , B =  {\left[ {\begin{array}{cccc}    2 & 1 & 0 & 0 \\    1 & -1 & 0 & 0 \\    0 & 0 & 2 & 1 \\    0 & 0 & 1 & -1 \\   \end{array} } \right]} \]](https://allenchou.net/wp-content/ql-cache/quicklatex.com-b3ed23feb4a1c0964a20e5f10a1c335b_l3.png)
![Rendered by QuickLaTeX.com \[ (AB)_{ij} = \sum\limits_{k = 0}^{m - 1} {A_{ik} B_{kj}} \]](https://allenchou.net/wp-content/ql-cache/quicklatex.com-95dbdea036a6e37f283e6e1d3e7600e7_l3.png)
