How to Find the Quaternion Representing Rotation Between Two 3D Vectors

linear algebramatricesquaternionsrotationsvectors

I have two 3-D vectors:

$$
V_1 =
\left[
\begin{array}{r}
-0.9597 \\ -0.9597 \\ 8.8703
\end{array}
\right]
$$

and

$$
V_2 =
\left[ \begin{array}{r}
-0.9568 \\ -0.9368 \\ 8.8432
\end{array} \right]
$$

How would I find the quaternion matrix to represent the rotation between $V_1$ and $V_2$? Specifically, what algorithm would I have to utilize to find it? MatLab code would be of great use!

Thanks in advance.

Best Answer

First find the axis ${\bf n}$ and angle $\theta$ for the rotation and then create the quaternion as $$q = (\cos \frac{ \theta}{2}, {\bf n} \sin \frac{ \theta}{2})$$

The axis is simply perpendicular both vectors.

$$ {\bf n} = \frac{ {\bf v}_1 \times {\bf v}_2 }{\| {\bf v}_1 \times {\bf v}_2 \|} $$

The angle is

$$ \theta = \tan^{-1} \left( \frac{\| {\bf v}_1 \times {\bf v}_2 \|}{{\bf v}_1 \cdot {\bf v}_2} \right) $$

NOTE: $$ {\bf v}_1 \cdot {\bf v}_2 = \| {\bf v}_1 \| \| {\bf v}_2 \| \cos \theta$$ and $$\| {\bf v}_1 \times {\bf v}_2 \| = \| {\bf v}_1 \| \| {\bf v}_2 \| \sin \theta$$

Related Question