# distance from point to a line

The distance from a point P with coordinates $(x_{p},y_{p})\in\mathbb{R}^{2}$ to the line with equation $ax+by+c=0$ is given by $|ax_{p}+by_{p}+c|/\sqrt{a^{2}+b^{2}}$.

Proof Every point $x,y$ on the line is at some distance $\sqrt{(x-x_{p})^{2}+(y-y_{p})^{2}}$ from P. What we need to find is the minimum such distance. Our problem is

 $\min(x-x_{p})^{2}+(y-y_{p})^{2}$

subject to

 $ax+by+c=0$

This problem is solvable using the Lagrange multiplier method. We minimize

 $(x-x_{p})^{2}+(y-y_{p})^{2}+\lambda(ax+by+c)$

Calculating the derivatives with respect to $x,y$ and $\lambda$ and setting them to zero we get three equations:

 $\displaystyle 2x-2x_{p}+\lambda a=0$ (1) $\displaystyle 2y-2y_{p}+\lambda b=0$ (2) $\displaystyle 2ax+2by+2c=0$ (3)

Solving these leads to $x_{p}-x=a\frac{ax_{p}+by_{p}+c}{a^{2}+b^{2}}$ and $y_{p}-y=b\frac{ax_{p}+by_{p}+c}{a^{2}+b^{2}}$. We can now substitute these expressions into $\sqrt{(x-x_{p})^{2}+(y-y_{p})^{2}}$ and we get (after some simplification) the desired result.

Title distance from point to a line DistanceFromPointToALine 2013-03-22 15:24:30 2013-03-22 15:24:30 acastaldo (8031) acastaldo (8031) 7 acastaldo (8031) Result msc 51N20 DistanceOfNonParallelLines DistanceBetweenTwoLinesInR3 Envelope AngleBisectorAsLocus