3

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.

dantopa
  • 10,342
F.st
  • 33
  • 1
    There are multiple rotations that will take $V_1$ to $V_2$, you will need to choose one first. I.e. you will need to decide on the axis and angle of the rotation you want to apply. – Paul Aljabar Jul 12 '17 at 20:48
  • 1
    Welcome to Mathematics StackExchange! This short guide can help expand your MathJax knowledge: https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference – dantopa Jul 12 '17 at 21:05

2 Answers2

3

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$$

John Alexiou
  • 13,816
1

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).

MGirard
  • 318