I am struggling to understand the 3D rotation. 
The initial object position is $A(x_1, y_1, z_1).$ We need rotate it into $A'(x_2,y_2,z_2)$ about $z$-axis by angle $\angle A'PA=\theta.$ And we take $P$ be the any point in $z$-axis. It makes $\angle APS=\phi.$
Now we find $cos \phi= \frac{PS}{OP}=\frac{x_1}{r}\Rightarrow x_1=rcos \phi.$ But we know $OQ =x_1$ but here slides take $PS =x_1$ and they forcefully match the answer which is wrong.
My question is slides has wrong or my concepts is wrong? If both are wrong so how we find 3D rotation about any coordinate axis?


Suppose $P = (x, y, z) $ a point in $3D$.
We want to rotate $P$ about the $z$ axis.
Note that this rotation does not change the $z$ coordinate of $P$, and that the image of the $x$ and $y$ coordinates follow that of the usual $2D$ rotation.
Thus if $P' = (x', y', z')$ is the image of $P$ under a rotation about the $z$ axis by an angle $\theta$ then
$z' = z$
$x' = x \cos \theta - y \sin \theta $
$y' = x \sin \theta + y \cos \theta $
In matrix form
$\begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} \cos \theta && - \sin \theta && 0 \\ \sin \theta && \cos \theta && 0 \\ 0 && 0 && 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} $