Distance Between A Point And A Line

Here is an elementary geometric derivation of the formula:

Any (st.)line perpendicular to the line $$Ax+By+C=0\qquad\text{(1)}$$ is given by $$Bx-Ay+C'=0\qquad\text{(2)}$$ Since (2) has to pass through the point $(x_1,y_1)$ (WHY?), we have $C'=Ay_1-Bx_1$. So, (2) becomes $$Bx-Ay+Ay_1-Bx_1=0\Rightarrow \frac{x-x_1}{A}=\frac{y-y_1}{B}=t\text{ (say)}\qquad(3)$$ From (3), $x=At+x_1$ and $y=Bt+y_1$. This is (called) the parametric equation of the line (2). Each $t$ correspond a point in it and vice-verse. Our next task is to determine the value of $t$ such that (1) and (2) meet at that point. To do so, substituting the value of $x$ and $y$ in (1), we get $t=-\frac{Ax_1+By_1+C}{A^2+B^2}$. Hence the required distance is $$\sqrt{(x-x_1)^2+(y-y_1)^2}=\sqrt{A^2t^2+B^2t^2}=|t|\sqrt{A^2+B^2}=\frac{|Ax_1+By_1+C|}{\sqrt{A^2+B^2}}.$$


The distance $d$ between the point $P_1(x_{1},y_{1})$ and the line $r$ whose equation is $Ax+By+C=0$ can be derived algebraically as follows:

i) Find the equation of the straight line $s$ passing through $P_1$ and which is orthogonal to $r$. Call $P_2$ the intersecting point of $r$ and $s$.

ii) Find the co-ordinates of $P_2(x_{2},y_{2})$.

iii) Find the distance from $P_1$ to $P_2$. This distance is $d$.


For what it's worth, here's the outline using the "derivative approach". Since you tagged this as analytic geometry, I would think the splendid answers by Americo and Didier would be the better approach.

Rewriting your equation of the line for $B\ne0$ gives: $$ y={-Ax-C\over B}. $$ (If $B=0$, the line is vertical, and the problem is simple.)

If the point $(x, {-Ax-C\over B})$ is on the line, its distance to $(x_1,y_1)$ is $$ \tag{1}D=\sqrt{ (x_1-x)^2 + {\Bigl(y_1- { \textstyle{-Ax-C\over B}}\Bigr)^2 }}. $$

You want to find the smallest value of $D$. This is equivalent to finding the smallest value of $$ P(x)=D^2= (x_1-x)^2 + {\Bigl(y_1- { \textstyle{-Ax-C\over B}}\Bigr)^2 } $$

Now, it should be obvious that the distance from a point $p$ on the line to $(x_1,y_1)$ is big, if $p$ is "on an extreme end of the line". So, the minimum distance is attained at a point where $P'(x)=0$.

So, you need to find $P'(x)$, then solve $P'(x)=0$. I'll leave this for you...

You should only get one solution to $P'(x)=0$. The minimum of $P$, and hence the minimum of $D$, would then have to occur at this point . If you then plug this solution into (1), your formula will result after a bit of simplification.