Find the shortest distance between two lines in 3D 
Question :
The line $l_1$ passes through the points $( 0 , 0 , 10 )$ and $( 7 ,0 ,0 )$ and the line $l_2$ passes through the points $( 4, 6 ,0 )$ and $( 3 , 3 ,1 )$. Find the shortest distance between $l_1$ and $l_2$ .

I found that \begin{align}l_1 : r &= ( 7 , 0 ,0 ) + a ( 7 , 0 , -10 )\\
l_2 : r &= ( 3 , 3 ,1 ) + b ( -1 , -3 ,1 )\end{align} for $a,b\in\Bbb R$
Help me solve this question , thank you so much !
 A: You know what a point in each line looks like. You know how to find the distance between points. That gives you a function of $a,b$, which you must minimize.
In our case, a point on $l_1$ is $(7+7a,0,-10a)$, and $l_2$ is $(3-b,3-3b,1+b)$.
So the distance between these points is :
$$
\sqrt{(7+7a-3+b)^2 + (3b-3)^2 + (-10a-b+1)^2}
$$
Now, it's enough to minimize $(7+7a-3+b)^2 + (3b-3)^2 + (-10a-b+1)^2$ with respect to $a$ and $b$. If you know how to do this, then that will give you values of $a$ and $b$, for which the distance is the least.
If you do not, then tell me.
EDIT: 
Partial differentiating with respect to $a$ and $b$ and equating to zero, we get:
$$
14(4+7a+b) -20(-10a-b+1) = 0 ; 2(4+7a+b) + 6(3b-3) -2(-10a-b+1) = 0
$$ 
Solve these equations to get the minimizing $a,b$, and then find the distance.
A: The geometric approach is as follows:


*

*Step 1: Find a vector perpendicular to both lines.  In your case, the direction of the two lines is $\langle 7,0,-10\rangle$ and $\langle -1,-3,1\rangle$.  A vector perpendicular to both lines is given by the cross product
$$
\langle 7,0,-10\rangle\times\langle -1,-3,1\rangle=\langle -30,3,-21\rangle
$$

*Step 2: Find parallel planes containing each of the lines.  Since a point on the first line is $(7,0,0)$ and a point on the second line is $(3,3,1)$, a plane containing the first line is
$$
-30(x-7)+3(y-0)-21(z-0)=0
$$ 
and a plane containing the second line is
$$
-30(x-3)+3(y-3)-21(z-1)=0.
$$
We observe that the distance between the planes is the same as the distance between the lines.  Therefore, we need to find the distance between the planes.  The distance between two planes is the same as the distance between a point on one plane and the other plane.  In particular, we can find the distance between $(7,0,0)$ and the plane $-30(x-3)+3(y-3)-21(z-1)=0$.


*

*Step 3: To find the distance between two a point and a plane, we need a vector from the plane to the point and then project that onto the normal of the plane.  This is a fairly standard application of projections.  Since we know that $(3,3,1)$ is on the plane and $(7,0,0)$ is the point of interest, we look at the vector from $(3,3,1)$ to $(7,0,0)$ which is $\langle 4,-3,-1\rangle$.  The projection onto the normal is
$$
\|\operatorname{proj}_{\langle -30,3,-21\rangle}\langle4,-3,-1\rangle\|=\frac{|\langle -30,3,-21\rangle\cdot\langle4,-3,-1\rangle|}{\|\langle -30,3,-21\rangle\|}=\frac{108}{\sqrt{1350}}=\frac{36}{\sqrt{150}}.
$$
This is the distance between the planes, and hence, the lines.

A: Analytically:
Let the lines be defined by the vectors $pq$ and $rs$. The squared distance between any to points can be expressed as
$$d^2=(pr+a\ pq+b\ rs)^2.$$
You minimize it by differentiating on $a$ abd $b$, giving the system
$$\begin{cases}pq\cdot(pr+a\ pq+b\ rs)=0,\\rs\cdot(pr+a\ pq+b\ rs)=0.\end{cases}$$
This expresses that $pr+a\ pq+b\ rs$ is orthogonal to both $pq$ and $rs$, hence it is parallel to $pq\times rs$.
If we define the unit vector $u:=\dfrac{pq\times rs}{\|pq\times rs\|}$ we have:
$$pr+a\ pq+b\ rs=\lambda u.$$
Now we can eliminate $a$ and $b$ by taking the dot product with $u$ so that
$$pr\cdot u=\lambda.$$
Finally,
$$d=\sqrt{(pr+a\ pq+b\ rs)^2}=|\lambda|=|pr\cdot u|=\frac{|(pr,pq,rs)|}{\|pq\times rs\|}.$$

Geometrically:
Consider the common perpendicular between the two lines, and rotate space so that it becomes parallel to $oz$. Then the two lines are included in planes parallel to $oxy$ and the shortest distance is the distance between these planes, which is also the distance between the projections of the lines.
