If you are given the angle ($\alpha$) of the projection of the vector on the XZ plane, taken from X,
then it means that the projection lies on the line $z=\tan \alpha \, x$, i.e that the vector
lies on the plane
$$
\pi _{\,x\,z} :\quad x\sin \alpha - z\cos \alpha = 0
$$
Similarly for the angle $\beta$ rising from Y on the YZ plane we get
$$
\pi _{\,y\,z} :\quad y\sin \beta - z\cos \beta = 0
$$
Visually this is rendered by the following sketch
That means that the vector is normal to both the normals of the planes, which gives
$$ \bbox[lightyellow] {
\eqalign{
& {\bf r} = \pm \left| {\bf r} \right|\;{{{\bf n}_{\,{\bf \alpha }} \times {\bf n}_{\,{\bf \beta }} } \over {\left| {{\bf n}_{\,{\bf \alpha }} \times {\bf n}_{\,{\bf \beta }} } \right|}} = \cr
& \; = \pm \left| {\bf r} \right|\;\left[ {\left( {\matrix{ {\sin \alpha } \cr 0 \cr { - \cos \alpha } \cr
} } \right) \times \left( {\matrix{ 0 \cr {\sin \beta } \cr { - \cos \beta } \cr
} } \right)} \right]_{\,norm} = \cr
& = {{ \pm \left| {\bf r} \right|} \over {\sqrt {\cos ^{\,2} \beta \sin ^{\,2} \alpha + \sin ^{\,2} \beta } }}\;
\left( {\matrix{ {\cos \alpha \sin \beta } \cr {\cos \beta \sin \alpha } \cr {\sin \alpha \sin \beta } \cr
} } \right) = \cr
& = {{ \pm \left| {\bf r} \right|\;2\sqrt 2 } \over {\sqrt {6 - \cos \left( {2\left( {\alpha + \beta } \right)} \right) - \cos \left( {2\left( {\alpha - \beta }
\right)} \right) - \cos \left( {2\alpha } \right) - \cos \left( {2\beta } \right)} }}\; \cdot \cr
& \cdot \left( {\matrix{ {\cos \alpha \sin \beta } \cr {\cos \beta \sin \alpha } \cr {\sin \alpha \sin \beta } \cr
} } \right) \cr}
} \tag{1}$$
where the sign is to be taken appropriately: it will be plus
if the direction of the vector is chosen according to the "right hand rule".
Note that the expression for the vector is fully compatible wrt the exchange of $\alpha, \beta$
as it should be.
Also note that
$$ \bbox[lightyellow] {
{{r_{\,z} } \over {r_{\,x} }} = \tan \alpha \quad {{r_{\,z} } \over {r_{\,y} }} = \tan \beta
} $$
as required.
And finally note that the expression above is fully defined
for $0 < |\alpha|,\, |\beta| < pi$, as well as
for $ |\alpha| =0, \, \pi$ if $\beta \ne 0$
$$
{{\bf r} \over {\left| {\bf r} \right|}} = \left\{ {\matrix{
{\left( {1,0,0} \right)^T } & {\left| {\,\alpha = 0,\beta \ne 0} \right.} \cr
{\left( {0,\cos \beta ,\sin \beta } \right)^T } & {\left| {\,\alpha = \pi /2,\forall \beta } \right.} \cr
{\left( { - \sqrt 2 \sin \beta \,\mathop /\limits_{} \sqrt {1 - \cos \left( {2\beta } \right)} ,0,0} \right)^T } & {\left| {\,\alpha = \pi ,\;\beta \ne 0} \right.} \cr
} } \right.
$$
--- Conclusion ---
In reply to your comment, consider that the formula (1) above simply translates into
$$ \bbox[lightyellow] {
\left\{ \matrix{
x = r{{\cos \alpha \sin \beta } \over {\sqrt {\cos ^{\,2} \beta \sin ^{\,2} \alpha + \sin ^{\,2} \beta } }}\; \hfill \cr
y = r{{\cos \beta \sin \alpha } \over {\sqrt {\cos ^{\,2} \beta \sin ^{\,2} \alpha + \sin ^{\,2} \beta } }} \hfill \cr
z = r{{\sin \alpha \sin \beta } \over {\sqrt {\cos ^{\,2} \beta \sin ^{\,2} \alpha + \sin ^{\,2} \beta } }} \hfill \cr}
\right.\quad \Leftrightarrow \quad \left\{ \matrix{
r = \sqrt {x^{\,2} + y^{\,2} + z^{\,2} } \; \hfill \cr
{z \over x} = \tan \alpha \hfill \cr
{z \over y} = \tan \beta \hfill \cr} \right.
}\tag{1.a}$$
In $\mathbb R^n$ in any number of dimensions, with the usual distance function, if you have a line through the origin in the direction of a vector $\mathbf r,$ as you have in your first figure,
and any other vector $\mathbf v,$ the length of the projected vector you get by projecting
$\mathbf v$ onto the line of $\mathbf r$ is just the inner product (aka dot product)
$$ v_r = \left(\frac1{\lVert\mathbf r\rVert}\mathbf r\right) \cdot v. $$
In general, the vector $\frac1{\lVert\mathbf r\rVert}\mathbf r$ is simply a unit vector in the same direction as $\mathbf r.$
In two dimensions, with a vector $\mathbf r$ at an angle $\theta$ from the $x$ axis, it happens that the vector on the left side of that inner product is
$$ \frac1{\lVert\mathbf r\rVert} \mathbf r=
\begin{bmatrix}
\cos\theta \\
\sin\theta
\end{bmatrix},$$
and therefore the inner product is given by the matrix multiplication you showed.
In your three-dimensional case, you can set
$$\frac1{\lVert\mathbf r\rVert} \mathbf r=
\begin{bmatrix} f_1(\theta, \phi) \\
f_2(\theta, \phi) \\
f_3(\theta, \phi) \end{bmatrix},$$
that is, simply set $f_1(\theta, \phi),$ $f_2(\theta, \phi),$ and
$f_3(\theta, \phi)$ to the three coordinates of the unit vector in the direction $\theta,\phi.$ You can read these coordinates off your diagram.
(They are combinations of trigonometric functions of $\theta$ and $\phi$ which you've already written; just don't multiply by $R$.)
Best Answer
Does this figure help you? The "perspective of sensor" triangles give you the angles you need.
EDIT:
The boxed equations are the ones you want, if i've interpreted your question correctly. (See new image)
You can figure out a direction vector, because my $\beta$ and $\alpha$ are the co-latitude and azimuthal angles in polar coordinates, respectively.