# Rotate a vector towards a point

I'm trying to figure out how to rotate a vector towards a certain point in a 3D plane, but I can't seem to find a solution. Here's the problem.

From a given position $$P(x_P,y_P,z_P)$$, vector $$\vec{f}$$ originates, with $$\vec{f}=\begin{pmatrix} x_f\\y_f\\z_f \end{pmatrix}$$. Somewhere else in the plane is point $$M(x_M,y_M,z_M)$$. Now I'm trying to figure out how to, given an angle $$\theta$$, one could find a vector $$\vec{f'}$$ that's basically $$\vec{f}$$ rotated $$\theta$$ towards $$M$$.

The Angle of Rotation is the $$cos^{-1}$$ of the dot-product of normalized before and after vectors.
Here is a simple, explicit way: Let $$\vec{v} := M-P$$ and then $$\vec{g} := \vec{f}\times ( \vec{v} \times \vec{f} )$$. Now $$\vec{g}$$ is orthogonal to $$\vec{f}$$ and lies in the plane spanned by $$\vec{v}$$ and $$\vec{f}$$. Now normalize $$\vec g_0 = \frac{|\vec f|}{|\vec g|}\vec g$$ to the length of $$\vec f$$. Then $$f' = \cos(\theta) \vec f + \sin(\theta) \vec g_0$$.
How do we know we have not rotated in the wrong direction? By a well kown vector identity, $$\vec a\times(\vec b\times \vec c) = (\vec a\cdot \vec c)\vec b - (\vec a \cdot \vec b)\vec c$$, thus $$\vec{v}\cdot\vec{g} = |\vec{f}|^2 |\vec{v}|^2 - (\vec{f} \cdot \vec{v})^2$$, which is non-negative by Cauchy's inequality, hence the angle between $$\vec g$$ and $$\vec v$$ is acute. This means that $$\vec v$$ and $$\vec g$$ lie in the same half-plane with respect to $$\vec f$$.
• Thanks for the answer! One of my colleagues advised me to look into the Rodrigues’ rotation formula, which would result in (with $\vec{k} = \frac{\vec{g_0}}{||\vec{g_0}||}$): $\vec{f'} = \vec{f} \cos{(\theta)} + (\vec{k} \times \vec{f}) \sin{(\theta)} + \vec{k}(\vec{k} \cdot \vec{f})(1-\cos{(\theta)})$, which is way longer (and seems way less elegant) than your solution. However, how could you explain the equality between his and your solution? In other words, can you explain what you're doing the last step? – SuperSjoerdie Jun 10 '19 at 10:18
• @SuperSjoerdie In Rodrigues' formula, $\vec k$ is a given rotation axis, around which $\vec f$ is rotated. Since we want to rotate $\vec f$ towards $\vec v = M-P$, it only makes sense to rotate in the plane spanned by $\vec f$ and $\vec v$, thus $\vec k$ is a unit normal vector of this plane, i.e. $\vec f \times \vec v/|\vec f \times \vec v|$. The last term in the formula drops out, since $\vec k \cdot \vec f = 0$, in our case, and $\vec g_0 = \vec k \times \vec f$. – Josef E. Greilhuber Jun 10 '19 at 14:38