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?

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

3 Answers 3


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}$.

  • 1
    $\begingroup$ Thanks for your support $\endgroup$ 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.

  • $\begingroup$ 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)$. $\endgroup$
    – TonyK
    Aug 10, 2020 at 12:07
  • $\begingroup$ 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? $\endgroup$
    – mjw
    Aug 10, 2020 at 12:14
  • $\begingroup$ 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?) $\endgroup$
    – TonyK
    Aug 10, 2020 at 12:15
  • $\begingroup$ I have not learnt what Lagrange multipliers are , this proof might be useful for me later $\endgroup$ Aug 10, 2020 at 17:26
  • $\begingroup$ Thanks for your help $\endgroup$ Aug 10, 2020 at 17:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .