1. ## algebra nightmare

Hi folks,

I am trying to prove that the minimum distance d, between a line L1, $ax + by + c = 0$ and a point $A(x_{1}, y_{1})$ is given by the expression:

$d = \dfrac{ax_{1} + by_{1} + c}{\sqrt{a^2 + b^2}}$ .......................(1)

I have already worked out that the distance $d = |\vec{AB}|$ where

$\vec{AB} = (b \lambda - x_{1})i - (\dfrac{c}{b} + a \lambda - y_{1})j$

and

$\lambda = \dfrac{b^2 x_{1} - aby_{1} - ac}{b(a^2 + b^2)}$

The solution should be straightforward. Substitute $\lambda$ into $\vec{AB}$ and calculate $|\vec{AB}|$.

The problem is the algebra! I end up with so many terms and they don't cancel or resolve to equation 1.

It's a big ask to expect anyone to type in the answer but a few hints would be great.

2. ## Re: algebra nightmare

Originally Posted by s_ingram
Hi folks,

I am trying to prove that the minimum distance d, between a line L1, $ax + by + c = 0$ and a point $A(x_{1}, y_{1})$ is given by the expression:

$d = \dfrac{ax_{1} + by_{1} + c}{\sqrt{a^2 + b^2}}$ .......................(1)

I have already worked out that the distance $d = |\vec{AB}|$ where

$\vec{AB} = (b \lambda - x_{1})i - (\dfrac{c}{b} + a \lambda - y_{1})j$

and

$\lambda = \dfrac{b^2 x_{1} - aby_{1} - ac}{b(a^2 + b^2)}$

The solution should be straightforward. Substitute $\lambda$ into $\vec{AB}$ and calculate $|\vec{AB}|$.

The problem is the algebra! I end up with so many terms and they don't cancel or resolve to equation 1.

It's a big ask to expect anyone to type in the answer but a few hints would be great.
Substitute $\displaystyle \lambda$ into $AB$ and calculate does not give the correct answer

3. ## Re: algebra nightmare

The value of $\lambda$ provided is the value you get by evaluating the scalar product of $\vec{AB}$ and the vector parallel to the line L1 i.e. $bi - aj$ i.e. that value of $\lambda$ that defines a point on L1 that is perpendicular to the point A. Are you saying that this approach is incorrect?

4. ## Re: algebra nightmare

The approach is fine.
I assume $B$ is the point on $L_1$ such that $AB$ is perpendicular to $L_1$

Exactly.

6. ## Re: algebra nightmare

Originally Posted by s_ingram
Exactly.
the squared distance is a parabola with the min distance at it's vertex.

you have the vector $\left(x,~-\dfrac{a x + c}{b}\right)$, and the point $(x_1, y_1)$

The squared distance is

$\left( x - x_1\right)^2 + \left(-\dfrac{a x + c}{b}-y_1\right)^2$

if you expand all this out, and collect like powers of $x$ you obtain

$\left(\dfrac{a^2}{b^2}+1\right)x^2 +\left(\dfrac{2 a c}{b^2}+\dfrac{2 a y_1}{b}-2 x_1\right)x + \left(\dfrac{c^2}{b^2}+\dfrac{2 c y_1}{b}+x_1^2+y_1^2\right)$

and normalizing and simplifying gets you

$\Large \left(\frac{a^2}{b^2}+1\right) \left(x^2 + \left(\frac{2 \left(a \left(b y_1+c\right)-b^2 x_1\right)}{a^2+b^2}\right)x + \left(\frac{b^2 x_1^2+\left(b y_1+c\right)^2}{a^2+b^2}\right)\right)$

and the vertex is at $-\dfrac 1 2$ the coefficient of the $x$ term, i.e.

$\Large x_{min} = -\left(\frac{ \left(a \left(b y_1+c\right)-b^2 x_1\right)}{a^2+b^2}\right)$

The point of least distance squared is identical to the point of least distance so this $x_{min}$ is the value you are after. Now just do the final chug to get the $y$ value from the definition of your line.

7. ## Re: algebra nightmare

Thanks Romsek, this is certainly another way of doing the problem (and the parabola is a nice insight) but you have lost me on the vertex is half the coefficient of the x term. Why is that?

8. ## Re: algebra nightmare

"Completing the square". $\displaystyle y= (x- a)^2= x^2- 2ax+ a^2$ is a parabola having vertex at $\displaystyle (a, 0)$ so $\displaystyle u= x^2- 2ax+ a^2+ b^2$ is a parabola having vertex at (a, b). The x-coordinate is half of 2a, the coefficient of x.

9. ## Re: algebra nightmare

Originally Posted by s_ingram
The value of $\lambda$ provided is the value you get by evaluating the scalar product of $\vec{AB}$ and the vector parallel to the line L1 i.e. $bi - aj$ i.e. that value of $\lambda$ that defines a point on L1 that is perpendicular to the point A. Are you saying that this approach is incorrect?
we could say that AB is parallel to the vector (a,b) rather than saying it is perpendicular to (-b,a) so we get

$\text{AB}=\left(x_2-x_1,y_2-y_1\right)= \mu (a,b)$ for some $\mu$ where $B\left(x_2,y_2\right)$

Then solve the system

$|\text{AB}|=|\mu |\sqrt{a^2+b^2}$

and

$a x_2+b y_2+c=0$

giving the result

$d=\frac{\left|a x_1+b y_1+c\right|}{\sqrt{a^2+b^2}}$

10. ## Re: algebra nightmare

Very neat. You guys have all got great ways of solving this problem and this has been very helpful, so many thanks.
But my original question was about solving the algebraic nightmare that arose from trying to solve the problem in the way that was originally posed.
So, for a line $\vec{r} = \left( \begin{array}{c} 0 \\ -c/b \end{array} \right) + \lambda \left( \begin{array}{c} b \\ -a \end{array} \right)$ and a point $A (x_{1}, y_{1})$
I got the value of lambda required (see above) and the question said, and hence show that d = equation 1 from above. I am still left with my algebraic nightmare.

11. ## Re: algebra nightmare

I replaced $\displaystyle \lambda$ in $\displaystyle AB$ as you indicated in your original post and this is what I got

$\displaystyle \frac{c^2+2 a c x_1+a^2 x_1^2-2 b c y_1-2 a b x_1 y_1+4 a^2 y_1^2+b^2 y_1^2}{a^2+b^2}$

We are supposed to get this

$\displaystyle \frac{c^2+2 a c x_1+a^2 x_1^2+2 b c y_1+2 a b x_1 y_1+b^2 y_1^2}{a^2+b^2}$

which when factored gives

$\displaystyle \frac{\left(a x_1+b y_1+c\right){}^2}{a^2+b^2}$
and that is the correct answer

I presume that there is an error in your calculations of $\displaystyle AB$ and/or $\displaystyle \lambda$

and that is the source of the nightmare

I think we can sort this out if you tell us how you got $\displaystyle AB$ and $\displaystyle \lambda$

EDIT: in the expression for AB you should have $\displaystyle +y_1$ and not $\displaystyle -y_1$

(2) Case $\displaystyle b=0$ should be considered separately

12. ## Re: algebra nightmare

Idea, thanks for this.

I used the value of $\vec{AB}$ in the original post and took $\vec{AB}. \vec{m} = 0$ where $\vec{m}$ is the gradient vector bi - aj for a positive gradient. This gave a value for $\lambda$ that was provided in the question exactly as quoted in the original post. So, if there is an error it will be in AB, although AB was validated by giving the correct value of $\lambda$!
My problem is that $\vec{AB}$ of the form: si - tj and $|AB| = \sqrt{s^2 + t^2}$ the t term is $-( \dfrac{c}{b} + \dfrac{ab^2x_{1} - a^2by_{1} - a^2c}{b(a^2 + b^2)} - \dfrac{y_{1}}{1} )$ and when I square it the number of terms takes off.

13. ## Re: algebra nightmare

see my previous post. I added something

If you change the $\displaystyle -y_1$ to $\displaystyle +y_1$ it works.

$\displaystyle AB=\left\{\left(b \lambda -x_1\right),-\left(\frac{c}{b}+a \lambda +y_1\right)\right\}$

You do get a huge expression but it is a perfect square.

$\displaystyle \lambda =\frac{b^2x_1-a b y_1-a c}{b\left(a^2+b^2\right)}$ is OK

14. ## Re: algebra nightmare

many thanks Idea! You are perfectly right, I see I dropped a sign.
Now the fun starts. To verify the whole thing, but you have been great. When I saw the expression getting so large, I was convinced I was on the wrong track completely. Now you have confirmed that this is the way to go, so I will slog through it.
Great!