Distance from a point to a line
Geometry problem
From Wikipedia, the free encyclopedia
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. It is the length of the line segment that joins the point to the line and is perpendicular to the line. 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.
Cartesian coordinates
Line defined by an equation
In the case of a line in the plane given by the equation where , and are real constants with and not both zero, the distance from the line to a point is[1][2]: p.14
The point on this line that is closest to has coordinates:[3]
or equivalently
and
Horizontal and vertical lines
In the general equation of a line, , and cannot both be zero unless is also zero; in that case, the equation does not define a line. If and , the line is horizontal and has equation . The distance from to this line is measured along a vertical line segment of length in accordance with the formula. Similarly, for vertical lines the distance between the same point and the line is , as measured along a horizontal line segment.
Line defined by two points
If the line passes through two points and then the distance of from the line is:
The denominator of this expression is the distance between and . The numerator is twice the area of the triangle with its vertices at the three points, , and . See: Area of a triangle § Using coordinates. The expression is equivalent to , which can be obtained by rearranging the standard formula for the area of a triangle: , where is the length of a side, and is the perpendicular height from the opposite vertex.
Line defined by point and angle
If the line passes through the point with angle , then the distance of some point to the line is
Proofs
An algebraic proof
This proof is valid only if the line is neither vertical nor horizontal, that is, we assume that neither nor in the equation of the line is zero.
The line with equation has slope , so any line perpendicular to it will have slope (the negative reciprocal). Let be the point of intersection of the line and the line perpendicular to it which passes through the point . The line through these two points is perpendicular to the original line, so
Thus, and by squaring this equation we obtain:
Now consider,
using the above squared equation. But we also have,
since (m, n) is on ax + by + c = 0. Thus,
and we obtain the length of the line segment determined by these two points,
A geometric proof

This proof is valid only if the line is not horizontal or vertical.[5]
Drop a perpendicular from the point with coordinates to the line with equation . Label the foot of the perpendicular . Draw the vertical line through and label its intersection with the given line . At any point on the line, draw a right triangle whose sides are horizontal and vertical line segments with hypotenuse on the given line and horizontal side of length (see diagram). The vertical side of will have length since the line has slope .
and are similar triangles, since they are both right triangles and since they are corresponding angles of a transversal to the parallel lines and </math>UV</math> (both are vertical lines).[6] Corresponding sides of these triangles are in the same ratio, so:
If point has coordinates then and the distance from to the line is:
Since is on the line, we can find the value of ,
and finally obtain:[7]
A variation of this proof is to place at and compute the area of the triangle two ways to obtain that where is the altitude of drawn to the hypoteneuse of from . The distance formula can then used to express , , and in terms of the coordinates of and the coefficients of the equation of the line to get the indicated formula.[citation needed]
A vector projection proof

Let be the point with coordinates and let the given line have equation . Also, let be any point on this line and the vector starting at point . The vector n is perpendicular to the line, and the distance from point to the line is equal to the length of the orthogonal projection of on n. The length of this projection is given by:
Now,
- so and
thus
Since is a point on the line, , and so,[8]
Another formula
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 point is given with coordinates . The equation of a line is given by . The equation of the normal of that line which passes through the point is given .
The point at which these two lines intersect is the closest point on the original line to the point . Hence:
We can solve this equation for ,
The coordinate of the point of intersection can be found by substituting this value of into the equation of the original line,
Using the equation for finding the distance between points, , we can deduce that the formula to find the shortest distance between a line and a point is the following:
Recalling that and for the line with equation , a little algebraic simplification reduces this to the standard expression.[9]
Vector formulation

The equation of a line can be given in vector form:
Here a is the position of a point on the line, and n is a unit vector in the direction of the line. Then as scalar 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: is a vector from p to the point a on the line. Then is the projected length onto the line and so
is a vector that is the projection of onto the line. Thus
is the component of perpendicular to the line. 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.
Another vector formulation
If the line () goes through point and has a direction vector , the distance between point and line () is
where is the cross product of the vectors and and where is the vector norm of .
Note that cross products only exist in dimensions and and trivially in dimensions and (where the cross product is constant ).