I'm trying to verify my solution to the following problem: Given a vector $\textbf{a} = (x, y, z)$, where $x > 0, y > 0$ and $z > 0$, find the angle $\theta$ needed in order to rotate $\textbf{a}$ about the x-axis so that you get $\textbf{b} = (x, 0, z^*)$.
My solution: Given $\textbf{a}$ I find the angle that I need to rotate about the x-axis by projecting $\textbf{a}$ onto the yz-plane, then I normalize the projection and use the dot product to calculate the angle between the resulting vector and $(0,0,1)$. Hence:
Projecting: $Proj(\textbf{a}, \{\textbf{y}, \textbf{z}\}) = (0, y, z)$
Normalizing: $(0, y, z) / \sqrt(y^2 + z^2)$
The angle is: $\theta = \cos^{-1}((0,0,1)\cdot( 0, y, z) / \sqrt(y^2 + z^2)) = \cos^{-1}(z/\sqrt(y^2+z^2))$.
In order to verify my result I try to apply this rotation(https://en.wikipedia.org/wiki/Rotation_matrix) on $\textbf{a}$ expecting to get $\textbf{b}$:
$$ \left[ \begin{matrix} 1 & 0 & 0 \\ 0 & \cos(\cos^{-1}(z/\sqrt(y^2+z^2))) & -\sin(\cos^{-1}(z/\sqrt(y^2+z^2))) \\ 0 & \sin(\cos^{-1}(z/\sqrt(y^2+z^2))) & \cos(\cos^{-1}(z/\sqrt(y^2+z^2))) \end{matrix} \right] \left[ \begin{matrix} x \\ y \\ z \end{matrix} \right] $$
We know that the y-component should be zero, that is
$$ \begin{split} y\cos(\cos^{-1}(z/\sqrt(y^2+z^2))) -z\sin(\cos^{-1}(z/\sqrt(y^2+z^2))) = 0 \\ \Leftrightarrow yz/\sqrt(y^2+z^2) - z \sqrt(1 - z^2/(y^2+z^2)^2) = 0 \\ \Leftrightarrow y^2z^2/(y^2 + z^2) -z^2(1-z^2/(y^2 +z^2)^2) = 0 \\ \Leftrightarrow y^2(y^2 +z^2) - (y^2 +z^2)^2 + z^2 = 0 \\ \Leftrightarrow y^4 + y^2z^2 - y^4 - 2y^2z^2 - z^4 + z^2 = 0\\ \Leftrightarrow z^2 -y^2z^2-z^4 = 0 \\ \Leftrightarrow 1 - y^2 - z^2 = 0 \end{split} $$
Which is not zero...
This is what I would do: we want to rotate the vector into a vector with $x^2+ y^2+ z^2= u^2+ v^2$.
There are two ways to do this: rotate about the x-axis or rotate about the y-axis. (Actually we can use any axis in the xy-plane but those two are simplest.)
Don't worry about the specific angle, just use the fact that "a" is the cosine and "b" the sine. Rotating about the x-axis means using a matrix or the form $\begin{bmatrix}1 & 0 & 0 \\ 0 & a & b \\ 0 & -b & a \end{bmatrix}$. We must have $\begin{bmatrix}1 & 0 & 0 \\ 0 & a & b \\ 0 & -b & a \end{bmatrix}\begin{bmatrix}x \\ y \\ z \end{bmatrix}= \begin{bmatrix} x \\ ay+ bz \\ -by+ az\end{bmatrix}= \begin{bmatrix}u \\ v \\ 0\end{bmatrix}$.
So u= x, v= ay+ bz, and 0= -by+ az. Since u= x, v must equal $\sqrt{y^2+ z^2}$. From the last equation, b= az/y. Putting that into the second equation, $ay+ ab^2/y= a\frac{y^2+ z^2}{y}= v= \sqrt{y^2+ z^2}$ so $a= \sqrt{y^2+ z^2}\frac{y}{y^2+ z^2}= \frac{y}{\sqrt{y^2+ z^2}}$. Then $b= az/y= \frac{z}{\sqrt{y^2+ z^2}}$.
The rotation matrix is $\begin{bmatrix}1 & 0 & 0 \\ 0 & \frac{y}{d} & \frac{z}{d} \\ 0 & -\frac{z}{d} & \frac{y}{d}\end{bmatrix}$ with $d= \sqrt{y^2+ z^2}$.
Rotating about the y-axis, the same argument gives $\begin{bmatrix}\frac{x}{d} & 0 & \frac{z}{d} \\ 0 & 1 & 0 \\ -\frac{z}{d} & 0 & \frac{a}{d}\end{bmatrix}$