Distance from a point to a line

>

The distance from a point to a line is the shortest distance from a point to a line in Euclidean geometry. The distance from a point to a line will always turn out to be a perpendicular line. It can be calculated in the following ways. Knowing the shortest distance from a point to a line can be useful in a few situations. For example, The shortest distance to reach a road, quantifying the scatter on a graph, etc.

Cartesian coordinates

In the case of a line in the plane given by the equation ax + by + c = 0, where a, b and c are real constants with a and b not both zero, the distance from the line to a point (x0,y0) is[1]

$\operatorname{distance}(ax+by+c=0, (x_0, y_0)) = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}.$

[2]

Vector formulation

Illustration of the vector formulation.

Suppose we express the line in vector form:

$\mathbf{x} = \mathbf{a} + t\mathbf{n}$

where n is a unit vector. That is, a point, x, on the line is found by moving to a point a in space, then moving t units along the direction of the line.

The distance of an arbitrary point p to this line is given by

$\operatorname{distance}(\mathbf{x} = \mathbf{a} + t\mathbf{n}, \mathbf{p}) = \| (\mathbf{a}-\mathbf{p}) - ((\mathbf{a}-\mathbf{p}) \cdot \mathbf{n})\mathbf{n} \|.$

This more general formula can be used in dimensions other than two. This equation is constructed geometrically as follows: $\mathbf{a}-\mathbf{p}$ is a vector from p to the point a on the line. Then $(\mathbf{a} - \mathbf{p}) \cdot \mathbf{n}$ is the projected length onto the line and so

$((\mathbf{a} - \mathbf{p}) \cdot \mathbf{n})\mathbf{n}$

is a vector that is the projection of $\mathbf{a}-\mathbf{p}$ onto the line and so

$(\mathbf{a}-\mathbf{p}) - ((\mathbf{a}-\mathbf{p}) \cdot \mathbf{n})\mathbf{n}$

is the component of $\mathbf{a}-\mathbf{p}$ perpendicular to the line. The distance from the point to the line is then just the norm of that vector. [3]

Proof 1 (algebraic proof)

Let point (x,y) be the intersection between the line ax + by + c = 0 and the line perpendicular to ax+by+c = 0 passing through the arbitrary point (m,n).

Then it is necessary to show $a^2(n-y)^2 + b^2(m-x)^2 =2ab(m-x)(n-y).$

The above equation can be changed to $\frac{(a^2(n-y))}{(m-x)} = \frac{(b^2(m-x))}{(n-y)}$ because the slope of the line perpendicular to the line ax+by+c which contains (x,y) and (m,n) is b/a.

Then

$(a^2+b^2)((m-x)^2+(n-y)^2)=[a(m-x)+b(n-y)]^2=(am+bn+c)^2.$

So the distance is

$d=\sqrt{(m-x)^2+(n-y)^2}= \frac{|am+bn+c|}{\sqrt{a^2+b^2}}.$

[4]

Proof 2 (geometric proof)

Let the point S(m,n) connect to the point G(x,y) which is on the line ax+by+c=0, both lines being perpendicular to each other.

Draw a line am+bn+d=0, containing the point S(m,n), which is parallel to ax+by+c=0.

The absolute value of (c-d)/b, which is the distance of the line connecting the point G and some point F on the line am+bn+d=0 and parallel to the y-axis, is equal to the absolute value of (am+bn+c)/b.

Then the desired distance SG can be derived from the right triangle SGF, which is in the ratio of a:b:$\sqrt{a^2+b^2}$.

The absolute value of (am+bn+c)/b is the diagonal of the right triangle, so just multiply by the absolute value of b and divide by $\sqrt{a^2+b^2}$, and the proof is complete.

Another possible equation

By using the above Vector Formulation, it is possible to extract an equation to find the smallest distance of a point to a line. This can be found by deriving and substituting the following equations:

The Point P is given where $P_x$ and $P_y$ represent the x and y coordinates of the point P respectively. The equation of a line is given $y=mx+c$. The equation of the normal of that line which passes through the point P is given $y=\frac{P_x-x}{m}+P_y$.

The point at which these two lines intersect is the closest point on the original line to the point P. Hence:

$mx+c=\frac{P_x-x}{m}+P_y$

By rearranging, we can find the value of x at which they intersect.

$x=\frac{P_x+mP_y-mc}{m^2+1}$

The y coordinate can therefore be found by substituting the value of X into the equation of the original line.

$y=m\frac{(P_x+mP_y-mc)}{m^2+1}+c$

By using the equation for finding the geometric distance between 2 points $d=\sqrt{(X_2-X_1)^2+(Y_2-Y_1)^2}$, we can deduce the formula to find the shortest distance between a line and a point is the following:

$d=\sqrt{ \left( {\frac{P_x+mP_y-mc}{m^2+1}-P_x } \right) ^2 + \left( {m\frac{P_x+mP_y-mc}{m^2+1}+c-P_y }\right) ^2 }$

Note: If the line is perpendicular to the x-axis, one should use $m=0$, and swap $P_x$ and $P_y$.

Garner gives another proof and equation for the Cartesian Coordinate method here.[5]