# Finding the shortest line segment joining $2$ line segments in $\Bbb R^2$

On an online class, a lecturer gave the following question.

Let $$A$$ be any point on a line segment joining $$(4,0)$$ and $$(0,2)$$, and $$B$$ is any point on a line segment joining $$(8,0)$$ and $$(0,6)$$. What is the length of the shortest line segment $$AB$$?

What I tried to do is write A and B in parametric form using trigonometry as $$A(4\cos^2\theta,2\sin^2\theta)$$ and $$B(8\cos^2\theta,6\sin^2\theta)$$

Finding $$AB$$ comes out to be a $$2$$ variable expression with which I am not able relate to with any inequality. How to solve this?

• Try parameterizing each line segment, Aug 9, 2020 at 19:33
• There are a couple of ways to do this. Have you studied cross products? That may help.
– Karl
Aug 9, 2020 at 19:38
• @Karl: cross products don't help here. What helps is to draw a picture. Aug 10, 2020 at 12:18
• Thanks for the help sir Aug 10, 2020 at 17:23
• The question was so easy the when I drew the diagram Aug 10, 2020 at 17:25

Disclaimer: This answer is more of an intuitive and geometric answer than a linear algebra or optimization answer.

Let $$y_1=6-\frac{3}{4}x$$ and $$y_2=2-\frac{1}{2}x$$. These represent line segments $$B$$ and $$A$$ respectively. The point $$(4,0)$$ is the point where the shortest line segment connecting $$B$$ and $$A$$ will pass through. Intuitively, this is because the lines $$y_1$$ and $$y_2$$ will "converge" to a single point when moving rightwards along the x-axis and "diverge" away from each other when moving leftwards along the x-axis. That means that the closest point on $$A$$ from $$B$$ is the point $$(4,0)$$.

Now, the shortest distance to a point on $$B$$ from $$A$$ is a line. We will try to construct a right triangle in order to find this distance. Link to image of triangle. The line perpendicular to $$y_1$$ passing through point $$(4,0)$$ is line $$y_3=\frac{4}{3}x-\frac{16}{3}$$. This creates our right triangle. We create another right triangle by dropping a perpendicular from the intersection of lines $$y_1$$ and $$y_3$$. The triangle created by lines $$y=0, y_3,$$ and the perpendicular will be the right triangle we refer to through out the rest of the answer.

Setting $$y_1=y_3$$ to solve for $$x$$ yields $$x=\frac{136}{25}$$. This distance, however, is not the distance of the horizontal leg of the triangle, but $$\frac{136}{25}-4=\frac{36}{25}$$ is. To solve for the height of the triangle, we plug in $$x=\frac{136}{25}$$ into equation $$y_1$$ to yield $$y=\frac{192}{100}$$. By the Pythagorean theorem, the shortest distance, $$d$$, is $$d=\sqrt{\big(\frac{36}{25}\big)^2+\big(\frac{192}{100}\big)^2}=\frac{12}{5}$$.

• Thanks for your support Aug 10, 2020 at 17:25

When two segments in the plane are given this is a complicated geometric situation. You cannot expect that there is a simple once-for-all method that solves a particular problem connected with two arbitrary such segments. Draw a figure!

The triangle $$T$$ over the segment $$\sigma_2=[(8,0), (0,6)]$$ with right angle at$$(0,0)$$ contains the other segment $$\sigma_1=[(4,0), (0,2)]$$. All points in $$T$$ having the same distance $$d$$ to $$\sigma_2$$ are lying on a parallel to $$\sigma_2$$. Draw the parallel through $$A:=(4,0)\in \sigma_1$$. Since parallels nearer to $$\sigma_2$$ contain no points of $$\sigma_1$$ the point $$A$$ is nearest to $$\sigma_2$$ among all points of $$\sigma_1$$. You find the point $$B\in\sigma_2$$ by drawing the perpendicular $$y={4\over3}(x-4)$$ from $$A$$ to $$\sigma_2$$. A little computation then gives $$d=|AB|={12\over5}\ .$$

By Lagrange multipliers:

Let $$(p_1,p_2)$$ be the point on the first segment, and $$(q_1,q_2)$$ be the point on the second segment that minimizes the distance.

$$L=(p_1-q_1)^2+(p_2-q_2)^2 - \lambda \left(\frac{p_1}{4}+\frac{p_2}{2}-1\right) - \mu \left(\frac{q_1}{8}+\frac{q_2}{6}-1\right)$$

\begin{aligned} 0= \frac{1}{2} \frac{\partial L}{\partial p_1} &= p_1 - q_1-\frac{\lambda}{8}\\ 0= \frac{1}{2} \frac{\partial L}{\partial p_2} &= p_2 -q_2-\frac{\lambda}{4}\\ 0= \frac{1}{2} \frac{\partial L}{\partial q_1} &= q_1 -p_1-\frac{\mu}{16}\\ 0= \frac{1}{2} \frac{\partial L}{\partial p_2} &= q_2 -p_2-\frac{\mu}{12} \end{aligned}

Solving this system of equations:

$$\bbox[5px, border: 1pt solid green]{\lambda=\mu=0}$$ $$\bbox[5px, border: 1pt solid green]{(p_1,p_2)=(q_1,q_2)}$$

Thus, the Lagrange multiplier solution requires that the two points are actually the same point, and lie at the intersection of the two lines.

Since the problem specifies that only the two line segments are allowable, this method fails to produce the solution.

@TonyK pointed out in the comments, if the line segments were permitted to continue (they are not), the solution would have been the point of intersection. Since this is not in the feasible region, the solution will be at the boundary (an endpoint of one of the segments). The distance is the perpendicular distance from $$(0,4)$$ to the other segment. @CSquared worked it out yesterday.

• This can't be right, for two reasons: (i) you have not used the finiteness of the line segments in your answer. So you should get that the minimum distance between the two lines is $0$. (ii) Just draw a picture, and you will see that the shortest line must go through $(4,0)$. Aug 10, 2020 at 12:07
• Fair enough! Both points are valid. A third point, the "solution" I obtained does not seem to be orthogonal to the bottom segment. I've got to rethink this. Would have thought Lagrange multipliers would work. Any idea why not? Perhaps there are algebraic errors?
– mjw
Aug 10, 2020 at 12:14
• It's not orthogonal to the bottom segment, because it goes through an end-point. (Incidentally, how could it possibly be orthogonal to both segments, unless it had zero length?) Aug 10, 2020 at 12:15
• I have not learnt what Lagrange multipliers are , this proof might be useful for me later Aug 10, 2020 at 17:26
• Thanks for your help Aug 10, 2020 at 17:27