Assume I have a Cartesian $xyz$ coordinate system with a point $p=(p_x,p_y,p_z)$. In addition a vector $n=(n_x,n_y,n_z)$ is given.
-
How do I rotate the coordinate system to obtain a new $uvw$ system such that the $w$-axis is parallel to the vector $n$?
-
How do I obtain the coordinates of $p$ in the $uvw$-system?
Best Answer
Based on the answer of @Muphrid and using the formula given at:
http://answers.google.com/answers/threadview/id/361441.html
I summarize the steps for later reference:
Let $\hat{n} = n/\|n\|$, $\theta=\cos^{-1}(\hat{k}\cdot \hat{n})$, $b=\hat{k}\times \hat{n}$, and $\hat{b}=(\hat{b}_x,\hat{b}_y,\hat{b}_z)=b/\|b\|$. Then define:
and
$$ Q=\begin{bmatrix} q_0^2+q_1^2-q_2^2-q_3^2 & 2(q_1q_2-q_0q_3) & 2(q_1q_3+q_0q_2)\\ 2(q_2q_1+q_0q_3) & q_0^2-q_1^2+q_2^2-q_3^2 & 2(q_2q_3-q_0q_1\\ 2(q_3q_1-q_0q_2) & 2(q_3q_2+q_0q_1) & q_0^2-q_1^2-q_2^2+q_3^2 \end{bmatrix}. $$
We then have:
The new coordinate of $p$ becomes $$ (p_u,p_v,p_w)=(p\cdot\hat{u},p\cdot\hat{v},p\cdot\hat{w}) $$