The problem I am trying to solve is that I am trying to rotate a rigid body and align it to the X axis in 3D space. I have chosen two points on the body (p1, p2). First I move the coordinates to align the origin to one of the two points. (Cartesian coordinates)
Then, I compute the angles with respect to XYZ $$\overrightarrow{dirVect}=p1-p2$$ $$ \angle{X} = cos^{-1} \left(\frac{\begin{bmatrix}1 & 0 & 0\end{bmatrix}.\overrightarrow{dirVect}}{|\overrightarrow{dirVect}|}\right)$$ $$ \angle{Y} = cos^{-1} \left(\frac{\begin{bmatrix}0 & 1 & 0\end{bmatrix}.\overrightarrow{dirVect}}{|\overrightarrow{dirVect}|}\right)$$ $$ \angle{Z} = cos^{-1} \left(\frac{\begin{bmatrix}0& 0 & 1\end{bmatrix}.\overrightarrow{dirVect}}{|\overrightarrow{dirVect}|}\right)$$
I now compute a Rotation Matrix for (using this MATLAB script)
$\angle{X}, \frac{\pi}{2}-\angle{Y},\frac{\pi}{2}-\angle{Z}$
on applying this rotation matrix to every point on the rigid body, I expect the point p2 to be on the X axis (X, 0, 0). It is not. What could I be doing wrong?