How to find the quaternion representing the rotation between two 3-D vectors? 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.
 A: 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$$ 
A: If you have access to Simulink, there is a function called vrrotvec which returns an angle-axis representation of the rotation between two 3d vectors ( see : https://www.mathworks.com/help/sl3d/vrrotvec.html ). Otherwise, you can get the axis by using the cross product of $V_1$ with $V_2$ and the angle by a dot product. 
You can convert to a quaternion by using $q = \cos(\theta/2) + (u_x \hat{i} + u_y \hat{j} + u_z \hat{k}) \sin (\theta/2)$, where $u_x$, $u_y$ and $u_z$ are the components of the rotation axis, $\theta$ is the rotation angle and $\hat{i}$, $\hat{j}$ and $\hat{k}$ are the components of the quaternion. See the wiki page on quaternions (https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation). 
