Rotate vector to face more in the direction of another vector

rotationsvectors

I have 2 vectors, lets say vector $a$ and vector $b$. I want to rotate vector $a$ to face more in the direction of vector $b$, but I want to have some maximum angle of the rotation. For example, if $a$ would be $(0, 0, 1)$, $b$ would be $(0, 1, 0)$ and the maximum angle 45°, I want to output $(0,\sqrt{0.5},\sqrt{0.5})$. I can do it in 2D, but I need it in 3D and there I have a problem with limiting the rotation to the angle. Is this possible in some way, that isn't much processing-heavy?

Best Answer

Define the unit vectors along $a$ and $b$ as $u_1 = \dfrac{a}{|a|} $ and $u_2 = \dfrac{b}{|b|} $.

First compute the angle between $a,b$ as $\phi = \cos^{-1} u_1 \cdot u_2 $

Then after rotating vector $a$ , the final angle between $a$ and $b$ is given by

$\psi = \max \{ 0, \phi - \theta_\text{MAX} \} $

This way, if $\theta_\text{MAX} $ is greater than $\phi $ then $\psi $ will be zero.

Now we need to express the final rotated vector $a'$ in terms of $u_1$ and $u_2$

A unit vector lying in the plane of $u_1$ and $u_2$ and perpendicular to $u_2$ is given by

$ u_3 = \left( \dfrac{u_2 \times u_1}{|u_2 \times u_1|} \right) \times u_2 $

Where $\times$ denotes cross product. Finally, the rotated vector $a'$ is

$ a' =|a| \left( (\cos \psi) u_2 + (\sin \psi) u_3 \right) $

Related Question