# Homogeneous transformation matrix (10)

Kinematics & Universal Numerics
September 19, 2019

## From axis-angle form to quaternion.

We can express a rotation in terms of axis-angle form. One way to write it is a (rotation axis, rotation angle) pair, or

 $\displaystyle({\mathbf{d}};\theta)=\left(\begin{bmatrix}d_{x}\\ d_{y}\\ d_{z}\end{bmatrix};\theta\right),$ (1)

where ${\mathbf{d}}$ is a 3D unit vector and $\theta\in[0,\pi]$. The other way is to write the product of the two:

 ${\mathbf{v}}:=\theta{\mathbf{d}}=\begin{bmatrix}\theta d_{x}\\ \theta d_{y}\\ \theta d_{z}\end{bmatrix}.$

If ${\mathbf{v}}$ is not a zero vector, then the way to recover (1) is simply

 \displaystyle\left\{\begin{aligned} \displaystyle\theta&\displaystyle=||{% \mathbf{v}}||_{2},\\ \displaystyle{\mathbf{d}}&\displaystyle={\mathbf{v}}/\theta.\end{aligned}\right.

Otherwise, if ${\mathbf{v}}={\mathbf{0}}_{3\times 1}$, then $\theta=0$ and we let ${\mathbf{d}}=[0,0,1]^{T}$ by convention.

There is a third way: we write it as a unit vector of size 4:

 $\displaystyle{\mathbf{q}}=(q_{0},q_{1},q_{2},q_{3})=(c_{\theta/2},s_{\theta/2}% d_{x},s_{\theta/2}d_{y},s_{\theta/2}d_{z}).$ (2)

To convert ${\mathbf{q}}$ to (1) is also simple:

 \displaystyle\left\{\begin{aligned} \displaystyle\theta&\displaystyle=2\text{% atan2}(s_{\theta/2},c_{\theta/2})=2\left(\sqrt{1-q_{0}^{2}},q_{0}\right)\in[0,% \pi],\\ \displaystyle{\mathbf{d}}&\displaystyle=[q_{1},q_{2},q_{3}]/s_{\theta/2}\text{% if \theta\neq 0, and [0,0,1]^{T} otherwise}.\end{aligned}\right.

The vector ${\mathbf{q}}$ here is a quaternion, a very powerful tool to study and analyze 3D rotation matrices. In this blog we do not give the complete mathematical definition of it nor enumerate all of its numerous useful properties. However, while we try to solve some interesting rotation problems, we will then mention some of those properties and give some derivations about them.

The first number $q_{0}$ in ${\mathbf{q}}$ is its scalar part, or real part. The last three numbers are ${\mathbf{q}}$’s imaginary parts—there are three imaginary units for a quaternion: $\boldsymbol{i}$, $\boldsymbol{j}$, and $\boldsymbol{k}$, such that

 $\boldsymbol{i}^{2}=\boldsymbol{j}^{2}=\boldsymbol{k}^{2}=\boldsymbol{i}% \boldsymbol{j}\boldsymbol{k}=-1,$

and

 $\boldsymbol{i}\boldsymbol{j}=-\boldsymbol{j}\boldsymbol{i}=\boldsymbol{k},% \quad\boldsymbol{j}\boldsymbol{k}=-\boldsymbol{k}\boldsymbol{j}=\boldsymbol{i}% ,\quad\boldsymbol{k}\boldsymbol{i}=-\boldsymbol{i}\boldsymbol{k}=\boldsymbol{j}.$

Hence we can also write ${\mathbf{q}}$ in (2) as

 $\displaystyle{\mathbf{q}}$ $\displaystyle=q_{0}+\boldsymbol{i}q_{1}+\boldsymbol{j}q_{2}+\boldsymbol{k}q_{3}$ $\displaystyle=c_{\theta/2}+s_{\theta/2}(\boldsymbol{i}d_{x}+\boldsymbol{j}d_{y% }+\boldsymbol{k}d_{z}).$