Rotating vector versus dot product

275 Views Asked by At

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.

enter image description here

1

There are 1 best solutions below

0
On

Problem is the definition of $\phi$ which should be

$$ \phi = \sin^{-1} \left(n_2\right) $$