Distance between two lines $L_1:\> x+y+z=6,\> x-2z=-5$; $L_2:\> x+2y=3,\> y+2z=3 $ Find the distance between the two lines defined by :
$$\mathbb L_{1}=
  \begin{cases}
                                   x+y+z=6 & \\
                                   x-2z=-5 &  \\ 
  \end{cases}$$
$$\mathbb L_{2}=
  \begin{cases}
                                   x+2y=3 & \\
                                   y+2z=3 &  \\ 
  \end{cases}$$

I know that if we have two lines :
$\mathbb L_{1}=P_1+tv_1$ and $\mathbb L_{2}=P_2+tv_2$,then the distance is given by :
$$d(\mathbb L_{1},\mathbb L_{2})=\frac{\left|\left(P_{2}-P_{1}\right)\cdot\left(v_{1}\times v_{2}\right)\right|}{\left|v_{1}\times v_{2}\right|}$$
But the problem is that thegiven equations are not in the mentioned form,and I 'm not sure even if they are line (the equations seems to be plane). So how to start?
 A: Parametrize the two lines as follows:
For $\mathbb L_{1}$, let $z=t$. Then, $x= -5+2t$ and $y = 11-3t$, which leads to $P_1=(-5,11,0)$ and $v_1=(2,-3,1)$.
For $\mathbb L_{2}$, let $z=s$. Then, $x= 3-2s$ and $y = -3+4s$, which leads to $P_2=(-3,3,0)$ and $v_2=(4,-2,1)$.
Thus, $ v_{1}\times v_{2} = (-1,2,8) $ and the distance is
$$d(\mathbb L_{1},\mathbb L_{2})=\frac{\left|\left(P_{2}-P_{1}\right)\cdot\left(v_{1}\times v_{2}\right)\right|}{\left|v_{1}\times v_{2}\right|}
= \frac{\left|(2,-8,0)\cdot(-1,2,8)\right|}{\left|(-1,2,8)\right|}
= \frac{18}{\sqrt{69}}
$$
A: Sketch of a general solution :

*

*step one : find $P_1$ and $P_2$ by solving the two systems of equations. In the general case the plane equations have three variables (this is why their intersection is a line meaning an infinity of points) so you need to set for example $z=0$


*step two : in order to find the directional vectors $v_1$ and $v_2$ we start with the two pairs of normal vectors to the planes whose intersections are the lines we’re studying. So for example with the first line the two normal vectors are $n_1=(1,1,1)^T$ and $n_1’=(1,0,-2)^T$ and a directional vector of the first line is orthogonal to the two normal vectors so for example we can take $v_1=n_1\times n_1’$ the vector product of the two normal vectors. Similarly $v_2=n_2\times n_2’$


*step three : With all this in hand we can apply the formula
A: This answer was written mostly to convince myself that this can be brute-forced by Lagrange multipliers. Anyway, we are trying to minimize
$$f(x,y,z,x',y',z') = (x-x')^2+(y-y')^2+(z-z')^2$$
with respect to constraints
$$ \begin{cases}
                                   g_1(x,y,z,x',y',z') = x+y+z-6=0 & \\
                                   g_2(x,y,z,x',y',z') = x-2z+5 =0&  \\ 
  \end{cases} \qquad \begin{cases}
                                   g_3(x,y,z,x',y',z') = x'+2y'-3 & \\
                                   g_4(x,y,z,x',y',z') = y'+2z'-3 &  \\ 
  \end{cases}$$
The point $(x,y,z,x',y',z')$ which minimizes $f$ will satisfy
$$\nabla f \in \operatorname{span}\{\nabla g_1, \nabla g_2,\nabla g_3,\nabla g_4\}.$$
The gradients are
$$\nabla f (x,y,z,x',y',z') = 2(x-x',y-y',z-z',x'-x,y'-y,z'-z)$$
$$\nabla g_1 (x,y,z,x',y',z') = (1,1,1,0,0,0)$$
$$\nabla g_2 (x,y,z,x',y',z') = (1,0,-2,0,0,0)$$
$$\nabla g_3 (x,y,z,x',y',z') = (0,0,0,1,2,0)$$
$$\nabla g_4 (x,y,z,x',y',z') = (0,0,0,0,1,2)$$
so denoting $(\mathbf{x}, \mathbf{y}, \mathbf{z}) = (x-x',y-y',z-z')$ it follows that
$$(\mathbf{x}, \mathbf{y}, \mathbf{z}) \in \operatorname{span}\{(1,1,1),(1,0,-2)\} \cap \operatorname{span}\{(1,2,0),(0,1,2)\}.$$
This intersection can be seen to be $\operatorname{span}\{(-1,2,8)\}$ since
$$(-1,2,8) = 2(1,1,1)-3(1,0,-2) = -(1,2,0)+4(0,1,2).$$
Therefore $(\mathbf{x}, \mathbf{y}, \mathbf{z}) = t(-1,2,8)$ for some $t \in \Bbb{R}$. We also know
$$ \begin{cases}
                                   x+y+z=6 \,\mid \cdot \,2& \\
                                   x-2z=-5 \,\mid \cdot \,(-3) &  \\ 
  \end{cases} \qquad \begin{cases}
                                   x'+2y'=3 \,\mid \cdot \,(-1) & \\
                                   y'+2z'=3 \,\mid \cdot \,4 &  \\ 
  \end{cases}$$
so
$$-x+2y+8z=27, \qquad -x'+2y'+8z'=9.$$
Subtracting gives $$18 = -\mathbf{x}+2\mathbf{y}-8\mathbf{z} = t\|(-1,2,8)\|^2 = 69t \implies t = \frac{18}{69}.$$
Now we have
$$f(x,y,z,x',y',z') = \|(\mathbf{x}, \mathbf{y}, \mathbf{z})\|^2 = t^2\|(-1,2,8)\|^2 = \frac{18^2}{69}$$
so finally
$$d = \frac{18}{\sqrt{69}}.$$
