# Find the shortest distance between two lines in 3D [duplicate]

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 !

• here you can find it geomalgorithms.com/a07-_distance.html Jun 5 '17 at 12:03
• Sketch: Step 1: Find a common normal to both lines using the cross product. Step 2: Find a pair of parallel planes containing the lines. Step 3: Find a point on one of the planes. Step 4: Find the distance between the point and the other plane. Jun 5 '17 at 12:06
• Jun 5 '17 at 12:14
• Hi @Dr.Sonnhard , First of all , thank you for helping me . Secondly ,I do not understand this formula , Can you explain me about this one ? Thank you Jun 5 '17 at 13:36

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.

• I do not know how to minimize it . :( Help me @@@ , I tried to annihilate the brackets . Hoever , it is not useful Jun 5 '17 at 12:09
• If you square it, you can use partial derivatives to minimize. Jun 5 '17 at 12:11
• @MichaelBurr yes, thank you for adding to this question. Jun 5 '17 at 12:12
• There is an error in the distance formula above. (The (-10a-b+1) should be (-10a-b-1). This has consequences for the following differentiation calculation. The simultaneous equations become:298a+34b=-76 and 34a+22b=8 giving a =-9/25 and b=23/25 and d via the adjusted formula is 2.939 Jan 22 at 12:54
• @twa14 Thank you, I will make the required changes. Jan 22 at 12:55

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.

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.