The distance $h$ from the point $P_0=(x_0,y_0,z_0)$ to the line passing through $P_1=(x_1,y_1,z_1)$ and $P_2=(x_2,y_2,z_2)$ is given by $h=2A/r$, where $A$ is the area of a triangle defined by the three points and $r$ is the distance from $P_1$ to $P_2$. The values of $r$ and $A$ can be computed as follows:
$r=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}$ and $A=\frac{1}{2}\sqrt{a_1^2+a_2^2+a_3^2},$
where
$a_1=x_0y_1+x_1y_2+x_2y_0 - (y_0x_1+y_1x_2+y_2x_0),\\
a_2=y_0z_1+y_1z_2+y_2z_0 - (z_0y_1+z_1y_2+z_2y_0),\\
a_3=x_0z_1+x_1z_2+x_2z_0 - (z_0x_1+z_1x_2+z_2x_0).$
Let $O$ be the origin, and let $\vec{OX}=(x_1,x_2),\vec{OY}=(y_1,y_2)$ and $\vec{OT}=(t_1,t_2)$.
Applying the law of cosines to $\triangle{OYT}$, one gets
$$YT=\sqrt{r_y^2+r_t^2-2r_yr_t\cos(\alpha_y-\alpha_t)}$$
Applying the law of cosines to $\triangle{XYT}$, one gets
$$YT^2=r_z^2+r_u^2-2r_zr_u\cos(\theta_z-\theta_u)$$
which can be written as
$$YT^2=\bigg(\bigg(\frac{r_z}{r_u}\bigg)^2+1-2\bigg(\frac{r_z}{r_u}\bigg)\cos(\theta_z-\theta_u)\bigg)r_u^2$$
so one gets
$$r_u=\frac{\sqrt{r_y^2+r_t^2-2r_yr_t\cos(\alpha_y-\alpha_t)}}{\sqrt{\bigg(\dfrac{r_z}{r_u}\bigg)^2+1-2\bigg(\dfrac{r_z}{r_u}\bigg)\cos(\theta_z-\theta_u)}}$$
and
$$r_z=\dfrac{r_z}{r_u}\times r_u=\frac{r_z}{r_u}\cdot\frac{\sqrt{r_y^2+r_t^2-2r_yr_t\cos(\alpha_y-\alpha_t)}}{\sqrt{\bigg(\dfrac{r_z}{r_u}\bigg)^2+1-2\bigg(\dfrac{r_z}{r_u}\bigg)\cos(\theta_z-\theta_u)}}$$
One has
$$r_y\cos\theta_y=r_x\cos\theta_x+r_z\cos\theta_z\tag1$$
$$r_y\sin\theta_y=r_x\sin\theta_x+r_z\sin\theta_z\tag2$$
$$r_t\cos\theta_t=r_x\cos\theta_x+r_u\cos\theta_u\tag3$$
$$r_t\sin\theta_t=r_x\sin\theta_x+r_u\sin\theta_u\tag4$$
It follows from $(1)-(3)$ and $(2)-(4)$ that
$$\cos\theta_y=\frac{K+r_t\cos\theta_t}{r_y},\qquad \sin\theta_y=\frac{L+r_t\sin\theta_t}{r_y}$$
where
$$K=r_z\cos\theta_z-r_u\cos\theta_u,\qquad L=r_z\sin\theta_z-r_u\sin\theta_u$$
Hence, one gets
$$1=\cos^2\theta_y+\sin^2\theta_y=\bigg(\frac{K+r_t\cos\theta_t}{r_y}\bigg)^2+\bigg(\frac{L+r_t\sin\theta_t}{r_y}\bigg)^2$$
which can be written as
$$(K+r_t\cos\theta_t)^2+(L+r_t\sin\theta_t)^2=r_y^2$$
$$K^2+r_t^2+2Kr_t\cos\theta_t+L^2+2Lr_t\sin\theta_t=r_y^2$$
$$2Kr_t\cos\theta_t+2Lr_t\sin\theta_t=r_y^2-K^2-L^2-r_t^2$$
$$\sqrt{(2Kr_t)^2+(2Lr_t)^2}\cos(\theta_t-p)=r_y^2-K^2-L^2-r_t^2$$
where
$$\cos p=\frac{2Kr_t}{\sqrt{(2Kr_t)^2+(2Lr_t)^2}},\sin p=\frac{2Lr_t}{\sqrt{(2Kr_t)^2+(2Lr_t)^2}}$$
So,
$$\theta_t=p+\arccos\bigg(\frac{r_y^2-K^2-L^2-r_t^2}{\sqrt{(2Kr_t)^2+(2Lr_t)^2}}\bigg)$$
$$\beta=\alpha_t-\theta_t=\alpha_t-p-\arccos\bigg(\frac{r_y^2-K^2-L^2-r_t^2}{\sqrt{(2Kr_t)^2+(2Lr_t)^2}}\bigg)$$
$$\theta_y=\alpha_y-\beta=\alpha_y-\alpha_t+p+\arccos\bigg(\frac{r_y^2-K^2-L^2-r_t^2}{\sqrt{(2Kr_t)^2+(2Lr_t)^2}}\bigg)$$
It follows from $(1)(2)$ that
$$r_x=\sqrt{(r_x\cos\theta_x)^2+(r_x\sin\theta_x)^2}$$
$$=\sqrt{(r_y\cos\theta_y-r_z\cos\theta_z)^2+(r_y\sin\theta_y-r_z\sin\theta_z)^2}\tag4$$
Finally, $\theta_x$ can be determined by $(1)(2)(4)$.
Added :
We have already got $r_u$ and $r_z$.
Also, we have already seen that
$$(1)(2)(3)(4)\implies \cos(\theta_t-p)=M\quad \text{where}\quad M=\frac{r_y^2-K^2-L^2-r_t^2}{\sqrt{(2Kr_t)^2+(2Lr_t)^2}}$$
from which one gets
$$\theta_t=p\color{red}{\pm}\arccos(M)$$
where $\arccos (M)$ is such that
$$\cos(\arccos(M))=M\qquad\text{and}\qquad \color{red}{0\leqslant\arccos(M)\leqslant \pi}$$
So, one gets
$$\beta=\alpha_t-\theta_t=\alpha_t-p\mp\arccos(M)$$
and
$$\theta_y=\alpha_y-\beta=\alpha_y-\alpha_t+p\pm\arccos(M)$$
It follows from these that
$$(1)(2)(3)(4)$$
$$\implies (\theta_t,\beta,\theta_y)=(p+\arccos(M),\alpha_t-p-\arccos(M),\alpha_y-\alpha_t+p+\arccos(M)),(p-\arccos(M),\alpha_t-p+\arccos(M),\alpha_y-\alpha_t+p-\arccos(M))$$
For sufficiency, one finally has to check if each of these satisfies $(1)(2)(3)(4)$.
Best Answer
Look for a solution $t$ of the vector equation $$(a,b,c,d) = (1-t) \cdot (x_1,y_1,z_1,y_1) + t (x_2,y_2,z_2,u_2) $$