Minimum Distance from an Arbitrary Point in Two Dimensions and a Line Using Lagrange Multipliers

487 Views Asked by At

I need to find the minimal distance between a point $(x_0,y_0)$ and a line $ax+by = c$ for some constants $a,b,c ∈ ℝ$ using the Lagrange Multiplier Method.

Knowing the distance between two points, $(x_0,y_0)$ and $(x,y)$ is given by the following equation, I know that I need to minimise this equation.

$D = \sqrt{(x-x_0)^2 + (y-y_0)^2)}$

I also know that $D_{min}$ = $D^2_{min}$ , which will make it easier to use the Lagrange Method since I can "discard" the square root.

Then I let:

$f(x,y) = D^2 = (x-x_0)^2 + (y-y_0)^2$

Since this distance must be on the line $ax + by = c$ , I set my constraint:

$G(x,y) = ax + by - c = 0$

Then:

$∇f = <2x-2x_0, 2y-2y_0> ; ∇G = < a, b >$

Using the Lagrange Method for some constant $λ$, we have:

$∇f = λ∇G \Rightarrow < 2x-2x_0, 2y-2y_0 > = λ < a, b>$

Eliminating $λ$, we have:

$y = y_0 + \frac ba (x-x_0)$

Plugging this into my original constraint, $G(x,y)$, we have:

$G(x,y) = ax + b(y_0 + \frac ba (x-x_0)) = 0$

Solving for $x$, we have:

$x = \frac { c+ \frac {b^2}{a}{x_0} - by_0 }{a + \frac {b^2}a}$

Plugging back in once more, we have:

$y = \frac ba \left( \frac { c+ \frac {b^2}{a}{x_0} - by_0 }{a + \frac {b^2}a} \right) - \frac ba{x_0} + y_0$

The Hessian seems to confirm that any critical point of $f$ will be a local maximum of $f$, but the overall complexity of the point I found is making me question whether I took the right approach.

If I plug back these coordinates into $D$, I should get the minimum distance.

$D = \sqrt{\left(\frac { c+ \frac {b^2}{a}{x_0} - by_0 }{a + \frac {b^2}a}-x_0\right)^2 + \left(\frac ba \left( \frac { c+ \frac {b^2}{a}{x_0} - by_0 }{a + \frac {b^2}a} \right) - \frac ba{x_0})^2\right)}$

This seems unnecessarily complicated and wrong. Where did I go wrong (if I did)?

2

There are 2 best solutions below

0
On BEST ANSWER

Let me restart the problem from scratch.

You want to minimize $$F=(x-x_0)^2+(y-y_0)^2+\lambda (a x+b y-c)\tag 1$$ Computing the partila derivatives with respect to $x$ and $y$ and setting them equal to $0$ gives $$\frac{\partial F}{\partial x}=2(x-x_0)+a \lambda=0 \implies x=x_0-\frac 12 a \lambda\tag 2$$ $$\frac{\partial F}{\partial y}=2(y-y_0)+b \lambda=0 \implies y=y_0-\frac 12 b \lambda\tag 3$$ Now $$\frac{\partial F}{\partial \lambda}=ax+by-c=-\frac{1}{2} \lambda \left(a^2+b^2\right)+a {x_0}+b {y_0}-c\tag 4$$ $$\frac{\partial F}{\partial \lambda}=0 \implies \lambda=\frac{2 (a {x_0}+b {y_0}-c)}{a^2+b^2}$$ So, from $(2)$ and $(3)$, after simplifications $$x=\frac{b^2 {x_0}-a b {y_0}+a c}{a^2+b^2}\qquad \text{and} \qquad y=\frac{a^2 {y_0}-a b {x_0}+b c}{a^2+b^2}$$ making after simplifications

$$(x-x_0)^2+(y-y_0)^2=\frac{(ax_0+by_0-c)^2}{a^2+b^2}$$ which is the square of the well known distance of a point to a straight line.

0
On

There isn't anything wrong with what you did; you just made the algebra more difficult than it needed to become...

From your Lagrange equations, you arrive at $ \ a(y - y_0) \ = \ b (x - x_0) \ \ . $ The line you found has slope $ \ \frac{b}{a} \ , $ while the given line $ \ ax \ + \ by \ - \ c \ = \ 0 \ $ has slope $ \ -\frac{a}{b} \ . $ So it is worth noting here that you have incidentally demonstrated the proposition from classical geometry that the shortest distance from a line to a point external to the line is along a perpendicular to the line (the so-called "perpendicular distance").

We may alternatively express the result in this manner. The given line may be parameterized using

$$ ax \ + \ by \ = \ c \ \ \rightarrow \ \ a·(X \ + \ bt) \ + \ b·(Y \ - \ at) \ = \ c $$ $$ \Rightarrow \ \ x \ = \ X \ + \ bt \ \ , \ \ y \ = \ Y \ - \ at \ \ , $$

with $ \ (X,Y) \ $ being a "reference point" on the line. So a direction vector for the given line is $ \ \overrightarrow{v} \ = \ \langle \ b \ , \ -a \ \rangle \ \ . $ If we make $ \ (X \ , \ Y) \ $ the point on the given line that is closest to $ \ (x_0 \ , \ y_0) \ $ , so that the vector from the external point to that point is $ \ \langle \ (X-x_0) \ , \ (Y-y_0) \ \rangle \ $ , then your result may be understood as

$$ b(X-x_0) \ - \ a(Y-y_0) \ \ = \ \ 0 \ \ = \ \ \overrightarrow{v} \ · \ \langle \ (X-x_0) \ , \ (Y-y_0) \ \rangle \ \ , $$

this dot product telling us that these vectors are perpendicular.

As for the distance formula, if we don't need to have the actual coordinates of the closest point on the line, we can start with the distance-squared equation $ \ D^2 \ = \ (x-x_0)^2 \ + \ (y-y_0)^2 \ $ and use your result $ \ (y - y_0) \ = \ \frac{b}{a} · (x - x_0) \ $ to write

$$ \ D^2 \ = \ (x-x_0)^2 \ + \ \left( \frac{b^2}{a^2} \right) · (x-x_0)^2 \ \ = \ \ \left( \frac{a^2 \ + \ b^2}{a^2} \right) · (x-x_0)^2 \ \ . $$

The given line equation may be written as $$ \ ax \ + \ by \ = \ c \ \ \rightarrow \ \ a·(x \ - \ x_0) \ + \ b·( y \ - \ y_0) \ = \ c \ - \ ax_0 \ - \ by_0 \ \ . $$

We may again apply your result to obtain

$$ a·(x \ - \ x_0) \ + \ b·( y \ - \ y_0) \ \ = \ \ a·(x \ - \ x_0) \ + \ b·\frac{b}{a} · (x \ - \ x_0) $$ $$ = \ \ \left( \frac{a^2 \ + \ b^2}{a} \right) · (x \ - \ x_0) \ \ = \ \ c \ - \ ax_0 \ - \ by_0 \ \ . $$

Upon squaring both sides of this equation, we find

$$ \left( \frac{(a^2 \ + \ b^2)^2}{a^2} \right) · (x - x_0)^2 \ \ = \ \ (a^2 \ + \ b^2)·D^2 \ \ = \ \ (c \ - \ ax_0 \ - \ by_0)^2 $$

$$ \Rightarrow \ \ D^2 \ \ = \ \ \frac{(c \ - \ ax_0 \ - \ by_0)^2}{a^2 \ + \ b^2} \ \ \Rightarrow \ \ D \ \ = \ \ \frac{| \ c \ - \ ax_0 \ - \ by_0 \ |}{\sqrt{a^2 \ + \ b^2}} \ \ . $$

[Should you require the coordinates of the closest point on the given line, the relations $ \ \left( \frac{a^2 \ + \ b^2}{a} \right) · (X - x_0) \ \ = \ \ c \ - \ ax_0 \ - \ by_0 \ $ and $ \ (Y - y_0) \ = \ \frac{b}{a} · (X - x_0) \ $ will deliver them.]