# Rotating vector versus dot product

Suppose that I have a vector

$$v = [v_0, v_1, v_2]^T$$

which I want to project to

$$n = [n_0, n_1, n_2]^T$$

I did this with dot product of $$v$$ and $$n$$. As an alternative way, I wanted to rotate coordinate system and express $$v$$ in new coordinate system. I rotated coordinate system such that x axis is parallel to $$n$$ (or $$x^{\prime}$$ in figure). In new coordinate system, I expected component of $$v$$ in $$n$$ or $$x^{\prime}$$ axis to be equal to $$v \cdot n$$ in old coordinate system. I did $$Rv$$ with rotation matrix

$$R = \begin{bmatrix} \cos \theta \cos \phi && \cos \theta \sin \phi && \sin \theta\\ -\sin \phi && \cos \phi && 0\\ -\sin \theta \cos \phi && -\sin \theta \sin \phi && \cos \theta \end{bmatrix}$$

where, $$\theta$$ and $$\phi$$ are obtained with

$$\theta = \text{atan2} \left(\frac{n_1}{n_0}\right)\\ \phi = \text{atan2} \left(\frac{n_2}{\lvert n_0 \rvert}\right)$$

Then I wanted to try an example. $$v=[111.6, 14.701, 0]^T$$, $$n=[0.349026, 0.919137, -0.182667]^T$$. The results I get from two methods are different (app. 52 vs 47). Clearly, I am misunderstanding something. May you spot the mistake please.

• Did you take into account that $n$ is not quite a unit vector? I agree that the result of the dot product should stay the same after the rotation. – Jaap Scherphuis Dec 11 '20 at 15:21
• The numbers are provided are truncated. Edited to provide numbers with more precision. – Shibli Dec 11 '20 at 15:24
• Are you sure you got the rotation matrix correct? The first entry seems to be wrong: Wolfram alpha – Jaap Scherphuis Dec 11 '20 at 15:38
• That is a typo. In calculations the matrix was as the edited version. – Shibli Dec 11 '20 at 15:52

Problem is the definition of $$\phi$$ which should be
$$\phi = \sin^{-1} \left(n_2\right)$$