Distance from a point to a line

The distance (or perpendicular distance) from a point to a line is the shortest distance from a fixed point to any point on a fixed infinite line in Euclidean geometry.

The formula for calculating it can be derived and expressed in several ways.

Knowing the shortest distance from a point to a line can be useful in various situations—for example, finding the shortest distance to reach a road, quantifying the scatter on a graph, etc.

In Deming regression, a type of linear curve fitting, if the dependent and independent variables have equal variance this results in orthogonal regression in which the degree of imperfection of the fit is measured for each data point as the perpendicular distance of the point from the regression line.

The distance from (x0, y0) to this line is measured along a vertical line segment of length |y0 - (-c/b)| = |by0 + c| / |b| in accordance with the formula.

The numerator is twice the area of the triangle with its vertices at the three points, (x0,y0), P1 and P2.

, which can be obtained by rearranging the standard formula for the area of a triangle:

, where b is the length of a side, and h is the perpendicular height from the opposite vertex.

The line with equation ax + by + c = 0 has slope -a/b, so any line perpendicular to it will have slope b/a (the negative reciprocal).

Thus, and we obtain the length of the line segment determined by these two points, This proof is valid only if the line is not horizontal or vertical.

[5] Drop a perpendicular from the point P with coordinates (x0, y0) to the line with equation Ax + By + C = 0.

Label the foot of the perpendicular R. Draw the vertical line through P and label its intersection with the given line S. At any point T on the line, draw a right triangle TVU whose sides are horizontal and vertical line segments with hypotenuse TU on the given line and horizontal side of length |B| (see diagram).

The vertical side of ∆TVU will have length |A| since the line has slope -A/B.

∆PRS and ∆TVU are similar triangles, since they are both right triangles and ∠PSR ≅ ∠TUV since they are corresponding angles of a transversal to the parallel lines PS and UV (both are vertical lines).

[6] Corresponding sides of these triangles are in the same ratio, so: If point S has coordinates (x0,m) then |PS| = |y0 - m| and the distance from P to the line is: Since S is on the line, we can find the value of m, and finally obtain:[7] A variation of this proof is to place V at P and compute the area of the triangle ∆UVT two ways to obtain that

where D is the altitude of ∆UVT drawn to the hypoteneuse of ∆UVT from P. The distance formula can then used to express

in terms of the coordinates of P and the coefficients of the equation of the line to get the indicated formula.

[citation needed] Let P be the point with coordinates (x0, y0) and let the given line have equation ax + by + c = 0.

The vector n is perpendicular to the line, and the distance d from point P to the line is equal to the length of the orthogonal projection of

on n. The length of this projection is given by: Now, thus Since Q is a point on the line,

, and so,[8] It is possible to produce another expression to find the shortest distance of a point to a line.

This derivation also requires that the line is not vertical or horizontal.

The equation of the normal of that line which passes through the point P is given

, we can deduce that the formula to find the shortest distance between a line and a point is the following: Recalling that m = -a/b and k = - c/b for the line with equation ax + by + c = 0, a little algebraic simplification reduces this to the standard expression.

Then as scalar t varies, x gives the locus of the line.

The distance of an arbitrary point p to this line is given by This formula can be derived as follows:

The distance from the point to the line is then just the norm of that vector.

[10] This more general formula is not restricted to two dimensions.

If the line (l ) goes through point A and has a direction vector

Note that cross products only exist in dimensions 3 and 7 and trivially in dimensions 0 and 1 (where the cross product is constant 0).

Diagram for geometric proof
Diagram for vector projection proof
Diagram for vector projection proof
Illustration of the vector formulation.