- The green arrow is the out-of-plane vector
- the light blue arrow is the plane vector
Calculation of $a$ angle
If you got the coordinates $x,y,z$ and $x_p,y_p,0$ then the most generic way to use is through the dot product and the inverse cosine.
I.e.
- the vector in the projection plane will have direction:
$$v_{plane} = \begin{bmatrix} x-x_p\\ y-y_p\\ 0\end{bmatrix}$$
and the unit direction vector would be:
$$e_{plane} = \frac{1}{||v_{plane}||}\begin{bmatrix} x-x_p\\ y-y_p\\0\end{bmatrix}=\frac{1}{\sqrt{(x-x_p)^2+ (y-y_p)^2}}\begin{bmatrix} x-x_p\\ y-y_p\\ 0\end{bmatrix}$$
Similarly, the out of plane vector is:
$$v_{out} = \begin{bmatrix} x-x_p\\ y-y_p\\ z\end{bmatrix}$$
and the corresponding unit direction vector would be:
$$e_{out} = \frac{1}{||v_{out}||}\begin{bmatrix} x-x_p\\ y-y_p\\z\end{bmatrix}=\frac{1}{\sqrt{(x-x_p)^2+ (y-y_p)^2 + z^2}}\begin{bmatrix} x-x_p\\ y-y_p\\ z\end{bmatrix}$$
The dot product of the unit vectors would be:
$$e_{out} \cdot e_{plane} = \frac{1}{\sqrt{(x-x_p)^2+ (y-y_p)^2 + z^2}}\begin{bmatrix} x-x_p\\ y-y_p\\ z\end{bmatrix}\cdot \frac{1}{\sqrt{(x-x_p)^2+ (y-y_p)^2}}\begin{bmatrix} x-x_p\\ y-y_p\\ 0\end{bmatrix}$$
$$e_{out} \cdot e_{plane} = \frac{( (x-x_p)^2 + (y-y_p)^2 )}{\sqrt{((x-x_p)^2+ (y-y_p)^2 + z^2) ((x-x_p)^2+ (y-y_p)^2)}}
$$
$$e_{out} \cdot e_{plane} = \frac{\sqrt{ (x-x_p)^2 + (y-y_p)^2 }}{\sqrt{(x-x_p)^2+ (y-y_p)^2 + z^2 }}
$$
At the same time:
$$e_{out} \cdot e_{plane} = ||e_{out}|| \cdot ||e_{plane}|| \cdot \cos(a)= 1\cdot 1\cdot \cos(a) = \cos(a) $$
therefore:
$$\cos(a) = \frac{\sqrt{ (x-x_p)^2 + (y-y_p)^2 }}{\sqrt{(x-x_p)^2+ (y-y_p)^2 + z^2 }}
$$
$$a = \arccos\left( \frac{\sqrt{ (x-x_p)^2 + (y-y_p)^2 }}{\sqrt{(x-x_p)^2+ (y-y_p)^2 + z^2 }}\right)
$$
(PS: please check the derivation for any mistakes/errors, because the final equation seems a bit too elegant)
Calculation of $\phi$
Calculation for $\phi$ angle can be expressed by the same equation but you can select a point on the x axis e.g. $(x, y, z) = (1,0, 0).$
In that case the equation will have the following form:
$$e_{out} \cdot e_{plane} = \frac{1}{\sqrt{(x-x_p)^2+ (y-y_p)^2 + 0^2}}\begin{bmatrix} x-x_p\\ y-y_p\\ 0\end{bmatrix}\cdot \begin{bmatrix} 1\\ 0\\ 0\end{bmatrix}$$
$$\phi = \arccos\left( \frac{x-x_p}{\sqrt{(x-x_p)^2+ (y-y_p)^2 }}\right)
$$