Understanding Quaternion
Complex number
The set of complex numbers is the sum of a real number and an imaginary number and has the form:
\[
z = a + bi \quad a, b\in \mathbb{R}, i^2 = -1
\]
It could also be stated that all Real numbers are complex numbers with \(b=0\)
and all imaginary numbers are complex numbers with \(a=0\).
.
Conjugate of a complex number
A conjugate of a complex number is another complex number that has the same real part as the original complex number, and the imaginary part has the same magnitude but opposite sign:
\[
z^\star = a - bi
\]
If we multiply a complex number with its conjugate, we get a real number:
\[
zz^\star = a^2 + b^2
\]
Absolute value of a complex number
\[
\|z\| = \sqrt{zz^\star} = \sqrt{a^2+b^2}
\]
Quotient of Two Complex Numbers
To compute the quotient of two complex numbers, we multiply the numerator and denominator by the complex conjugate of the denominator
\[
\begin{array}{rcl}z_1 & = & (a_1+b_1i) \\ z_2 & = & (a_2+b_2i) \\ \cfrac{z_1}{z_2} & = & \cfrac{a_1+b_1i}{a_2+b_2i} \\ & = & \cfrac{(a_1+b_1i)(a_2-b_2i)}{(a_2+b_2i)(a_2-b_2i)} \\ & = & \cfrac{a_1a_2-a_1b_2i+b_1a_2i-b_1b_2i^2}{a_2^2+b_2^2} \\ & = & \cfrac{a_1a_2+b_1b_2}{a_2^2+b_2^2}+\cfrac{b_1a_2-a_1b_2}{a_2^2+b_2^2}i \end{array}
\]
Power of i
We can find that the pattern of the power of i should be \((1,i,-1,-i,1,\dots)\). This pattern is similar to another pattern in form of \((x,y,-x,-y,x,\dots)\), which is generated by rotating a point 90° counter-clockwise on a 2D Cartesian plane.
** The Complex Plane **
We can also map complex numbers in a 2D grid called the Complex Plane by mapping the Real part on the horizontal axis and the Imaginary part on the vertical axis.
As shown in the figure above, we can say that if we multiply a complex number by \(i\), we can rotate the complex number through the complex plane at 90° increments.
Rotors
We can also perform arbitrary rotations in the complex plane by defining a complex number of the form:
\[
q=\cos\theta+i\sin\theta
\]
Mutiplying a complex number by the rotor \(q\) produces the general formula:
\[
qz =(\cos\theta+i\sin\theta)(a+bi)= a\cos\theta-b\sin\theta+(a\sin\theta+b\cos\theta)i
\]
We can write this equation in matrix form:
\[
\left[\begin{array}{c}a^\prime \\ b^\prime \end{array}\right] =
\left[\begin{array}{cc}\cos\theta&-\sin\theta\\ \sin\theta & \cos\theta \end{array}\right]
\left[\begin{array}{c}a \\ b \end{array}\right]
\]
We can clearly see that this is equivalent to rotate a point in the complex plane counter-clockwise about the origin.
Quaternions
We can extend the idea of the complex plane into 3-dimensional space by adding two imaginary numbers to our number system in addition to \(i\). The general form to express quaternions is
\[
q=s+xi+yj+zk~~s,x,y,z\in\mathbb{R}
\]
where
\[
i^2=j^2=k^2=ijk=-1
\]
and
\[
\begin{array}{ccc}ij=k & jk=i & ki=j \\ ji=-k & kj=-i & ik=-j\end{array}
\]
The relationship between i, j, k is quite similar to the cross product rules for the unit cartesian vectors:
\[
\begin{array}{ccc}\mathbf{x}\times \mathbf{y}=\mathbf{z} & \mathbf{y}\times \mathbf{z}=\mathbf{x} & \mathbf{z}\times \mathbf{x}=\mathbf{y} \\ \mathbf{y}\times \mathbf{x}=-\mathbf{z} & \mathbf{z}\times \mathbf{y}=-\mathbf{x} & \mathbf{x}\times \mathbf{z}=-\mathbf{y}\end{array}
\]
Quaternions as an Ordered Pair
We can also represent quaternions as an ordered pair:
\[
q=[s,\mathbf{v}]~~s\in\mathbb{R}, \mathbf{v}\in\mathbb{R}^3
\]
Quaternion Products
The product of quaternion can be expressed as:
\[
\begin{array}{rcl}
q_a & = & [s_a,\mathbf{a}] \\
q_b & = & [s_b,\mathbf{b}] \\
q_{a}q_{b} & = & [s_{a},\mathbf{a}][s_{b},\mathbf{b}] \\
& = & (s_{a}+x_{a}i+y_{a}j+z_{a}k)(s_{b}+x_{b}i+y_{b}j+z_{b}k) \\
& = & (s_{a}s_{b}-x_{a}x_{b}-y_{a}y_{b}-z_{a}z_{b}) \\
& & +(s_{a}x_{b}+s_{b}x_{a}+y_{a}z_{b}-y_{b}z_{a})i \\
& & +(s_{a}y_{b}+s_{b}y_{a}+z_{a}x_{b}-z_{b}x_{a})j \\
& & +(s_{a}z_{b}+s_{b}z_{a}+x_{a}y_{b}-x_{b}y_{a})k\\
& = & [s_{a}s_{b}-x_{a}x_{b}-y_{a}y_{b}-z_{a}z_{b}, \\ & & s_{a}(x_{b}\mathbf{i}+y_{b}\mathbf{j}+z_{b}\mathbf{k})+s_{b}(x_{a}\mathbf{i}+y_{a}\mathbf{j}+z_{a}\mathbf{k}) \\ & & +(y_{a}z_{b}-y_{b}z_{a})\mathbf{i}+(z_{a}x_{b}-z_{b}x_{a})\mathbf{j}+(x_{a}y_{b}-x_{b}y_{a})\mathbf{k}]
\end{array}
\]
And if we substitute
\[
\begin{array}{rcl}\mathbf{a} & = & x_{a}\mathbf{i}+y_{a}\mathbf{j}+z_{a}\mathbf{k} \\ \mathbf{b} & = & x_{b}\mathbf{i}+y_{b}\mathbf{j}+z_{b}\mathbf{k} \\ \mathbf{a}\cdot\mathbf{b} & = & x_{a}x_{b}+y_{a}y_{b}+z_{a}z_{b} \\ \mathbf{a}\times\mathbf{b} & = & (y_{a}z_{b}-y_{b}z_{a})\mathbf{i}+(z_{a}x_{b}-z_{b}x_{a})\mathbf{j}+(x_{a}y_{b}-x_{b}y_{a})\mathbf{k}\end{array}
\]
We can get
\[
[s_{a},\mathbf{a}][s_{b},\mathbf{b}]=[s_{a}s_{b}-\mathbf{a}\cdot\mathbf{b},s_{a}\mathbf{b}+s_{b}\mathbf{a}+\mathbf{a}\times\mathbf{b}]
\]
This is the general form of a quaternion product.
Real quaternion and pure quaternion
A Real Quaternion is a quaternion with a vector term of \(\mathbf{0}\):
\[
q=[s,\mathbf{0}]
\]
The product of two real quaternion is another real quaternion.
Similar to Real Quaternions, Hamilton also defined the Pure Quaternion as a quaternion that has a zero scalar term:
\[
q=[0,\mathbf{v}]
\]
According to the quaternion product rule, the product of two pure quaternions is:
\[
\begin{array}{rcl}q_{a}q_{b} & = & [0,\mathbf{a}][0,\mathbf{b}] \\ & = & [-\mathbf{a}\cdot\mathbf{b},\mathbf{a}\times\mathbf{b}]\end{array}
\]
Unit Quaternion
Given an arbitrary vector \(\mathbf{v}\), we can express this vector in both its scalar magnitude and its direction as such:
\[
\mathbf{v}=v\mathbf{\hat{v}}~\text{where}~v=|\mathbf{v}|~\text{and}~|\mathbf{\hat{v}}|=1
\]
Quaternion Conjugate
The quaternion conjugate can be computed by negating the vector part of the quaternion:
\[
\begin{array}{rcl}q & = & [s,\mathbf{v}] \\ q^* & = & [s,-\mathbf{v}]\end{array}
\]
And the product of a quaternion with its conjugate gives:
\[
\begin{array}{rcl}qq^* & = & [s,\mathbf{v}][s,-\mathbf{v}] \\ & = & [s^2-\mathbf{v}\cdot-\mathbf{v},-s\mathbf{v}+s\mathbf{v}+\mathbf{v}\times-\mathbf{v}] \\ & = & [s^2+\mathbf{v}\cdot\mathbf{v},\mathbf{0}] \\ & = & [s^2+v^2,\mathbf{0}]\end{array}
\]
Quaternion Norm
\[
\begin{array}{rcl}q & = & [s,\mathbf{v}] \\ |q| & = & \sqrt{s^2+v^2} = \sqrt{qq^\star}\end{array}
\]
Quaternion Normalization
A quaternion is normalized by dividing it by \(|q|\):
\[
q^{\prime}=\frac{q}{\sqrt{s^2+v^2}}
\]
Quaternion Inverse
The inverse of quaternion \(q^{-1}\) is:
\[
q^{-1}=\frac{q^*}{|q|^2}
\]
\[
qq^{-1}=\frac{qq^*}{|q|^2} = 1
\]
For unit-norm quaternions whose norm is 1, its inverse equals to its conjugate.
Quaternion Dot Product
Similar to vector dot-products, we can also compute the dot product between two quaternions by multiplying the corresponding scalar parts and summing the results:
\[
\begin{array}{rcl}q_1 & = & [s_1,x_1\mathbf{i}+y_1\mathbf{j}+z_1\mathbf{k}] \\ q_2 & = & [s_2,x_2\mathbf{i}+y_2\mathbf{j}+z_2\mathbf{k}] \\ q_1{\cdot}q_2 & = & s_{1}s_{2}+x_{1}x_{2}+y_{1}y_{2}+z_{1}z_{2}\end{array}
\]
We can also use the quaternion dot-product to compute the angular difference between the quaternions:
\[
\cos\theta=\frac{s_{1}s_{2}+x_{1}x_{2}+y_{1}y_{2}+z_{1}z_{2}}{|q_{1}||q_{2}|}
\]
Rotations
To rotate a vector \(\mathbf{p}\) by an angle \(\theta\) about an arbitrary axis \(\hat{v}\), we can construct the following quaternion:
\[
q=\left[\cos\frac{1}{2}\theta,\sin\frac{1}{2}\theta\mathbf{\hat{v}}\right]
\]
The point \(\mathbf{p}^\prime\) after rotation is:
\[
\mathbf{p}^\prime = \mathbf{q} \mathbf{p} \mathbf{q}^{-1}
\]
Quaternion to rotation matrix
Given a quaternion \(\mathbf{q} = q_0 + q_1 i + q_2 j + q_3 k\), the corresponding rotation matrix is
\[
\mathbf{R}=\left[\begin{array}{ccc}
1-2 q_2^2-2 q_3^2 & 2 q_1 q_2+2 q_0 q_3 & 2 q_1 q_3-2 q_0 q_2 \\
2 q_1 q_2-2 q_0 q_3 & 1-2 q_1^2-2 q_3^2 & 2 q_2 q_3+2 q_0 q_1 \\
2 q_1 q_3+2 q_0 q_2 & 2 q_2 q_3-2 q_0 q_1 & 1-2 q_1^2-2 q_2^2
\end{array}\right]
\]
Quaternion Interpolation
SLERP
SLERP stands for Spherical Linear Interpolation. SLERP provides a method to smoothly interpolate a point about two orientations.
\[
q_t=\frac{\sin(1-t)\theta}{\sin\theta}q_1+\frac{\sin{t\theta}}{\sin\theta}q_2
\]
Reference
https://www.3dgep.com/understanding-quaternions/