How do I find the rotation matrix between 2 normalized vectors coming from the origin

1.7k Views Asked by At

In my project, I have two vectors a normal vector $(0,0,1)$ (this is up in the program I'm using), and another normalized vector $(x,y,z)$. Suppose I rotate $(0,0,1)$ to a new $(a,b,c)$ which is also a normalized vector from the origin, how do I find the position of the new $(x,y,z)$ which rotated along with it. What I think might work is finding the rotation matrix between $(0,0,1)$ and $(a,b,c)$ and applying that rotation matrix to $(x,y,z)$, but I don't know how to find the rotation matrix between them. Below is an example, the red is $(0,0,1)$ in case 1 and $(a,b,c)$ in the rest of them, and blue is $(x,y,z)$ and $(x', y', z')$(or what I think $(x',y',z')$ is).

enter image description here

Also if it is indeed the rotation matrix between $(0,0,1)$ and $(a,b,c)$ that is being applied to $(x,y,z)$ I think it should be the simplest rotation matrix from $(0,0,1)$ to $(a,b,c)$, because if I'm not wrong there should be infinitely many rotation matrices between those two.

The motion of the rotation also matters, as I want $(0,0,1)$ to move to $(a,b,c)$ along a plane, as demonstrated below. The drawn orange vector on the right is perpendicular to this plane. enter image description here

2

There are 2 best solutions below

3
On BEST ANSWER

Given the vector $V = (0, 0, 1)$ and the unit vector $W = (a, b, c)$, and the vector $U = (x, y, z)$, you want to rotate $V$ into $W$ and along with this, you want to apply the same rotation to $U$ which will result in vector $U' = (x', y', z') $

It is required in the question that the axis of rotation be perpendicular to the plane that contains $V$ and $W$. Therefore, the unit vector along the axis is

$ u = \dfrac{ V \times W }{ \|V \times W\| } $

Since $V$ and $W$ are unit vectors, the angle of rotation $\phi$ satisfies

$ \cos(\phi) = V \cdot W $

and

$ \sin(\phi) = \| V \times W \| $

now, $\phi$ can be computed as $ \phi = \text{Atan2}(\cos(\phi), \sin(\phi) ) $

Now we apply the Rodrigues' Rotation matrix formula, which states that given an axis $u$ and an angle of rotation $\phi $ , then the rotation matrix is given by

$ R(u, \phi) = {u u}^T + (I - {u u}^T ) \cos(\phi) + S_u \sin(\phi) $

where

$S_u = \begin{bmatrix} 0 && - u_z && u_y \\ u_z && 0 && -u_x \\ -u_y && u_x && 0 \end{bmatrix} $

With this rotation matrix, we can now find $ U' $ as follows

$ U' = R \ U $

8
On
  1. Calculate the axis of rotation $v = \frac{(a,b,c)+(0,0,1)}{2} = \left(\frac{a}{2},\frac{b}{2},\frac{c+1}{2}\right)$
  2. Normalize the axis of rotation $u := \frac{v}{||v||_2} := (u_x,u_y,u_z)$
  3. Calculate the angle of rotation $\theta = \arccos\left(\frac{(a,b,c)\cdot(0,0,1)}{||(a,b,c)||_2||(0,0,1)||_2}\right) = \arccos\left(\frac{c}{||(a,b,c)||_2}\right) \stackrel{\text{if }||(a,b,c)||_2 = 1}{=} \arccos(c)$
  4. Use the Rotation matrix from axis and angle formula:

$$R = \begin{bmatrix} \cos(\theta)+u_x^2(1-\cos(\theta)) & u_xu_y(1-\cos(\theta))-u_z\sin(\theta) & u_xu_z(1-\cos(\theta))+u_y\sin(\theta) \\ u_yu_x(1-\cos(\theta))+u_z\sin(\theta) & \cos(\theta)+u_y^2(1-\cos(\theta)) & u_yu_z(1-\cos(\theta))-u_x\sin(\theta) \\ u_zu_x(1-\cos(\theta))-u_y\sin(\theta) & u_zu_y(1-\cos(\theta))+u_x\sin(\theta) & \cos(\theta)+u_z^2(1-\cos(\theta)) \end{bmatrix}$$ 5. Then, for any $(x,y,z) \in \mathbb{R}^3$, its rotated position will be $$R\cdot(x,y,z)^T = R \begin{bmatrix}x \\ y \\ z\end{bmatrix}$$