Distance from a point to a line - wikipedia 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 line in Euclidean geometry. It is the length of the line segment which 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. Contents 1 Cartesian coordinates 1.1 Line defined by an equation 1.2 Line defined by two points 2 Proofs 2.1 An algebraic proof 2.2 A geometric proof 2.3 A vector projection proof 3 Another formula 4 Vector formulation 5 Another vector formulation 6 See also 7 Notes 8 References 9 Further reading Cartesian coordinates Line defined by an equation 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 ( x, y ) is distance ⁡ ( a x + b y + c = 0, ( x 0, y 0 ) ) = a x 0 + b y 0 + c a 2 + b 2. ( displaystyle operatorname ( distance ) ( ax + by + c = 0, ( x_ ( 0 ), y_ ( 0 ) ) ) = ( \frac ( ax_ ( 0 ) + by_ ( 0 ) + c ) ( sqrt ( a ^ ( 2 ) + b ^ ( 2 ) ) ) ). ) The point on this line which is closest to ( x, y ) has coordinates : x = b ( b x 0 − a y 0 ) − a c a 2 + b 2 and y = a ( − b x 0 + a y 0 ) − b c a 2 + b 2. ( displaystyle x = ( \frac ( b ( bx_ ( 0 ) - ay_ ( 0 ) ) - ac ) ( a ^ ( 2 ) + b ^ ( 2 ) ) ) ( \text ( and ) ) y = ( \frac ( a ( - bx_ ( 0 ) + ay_ ( 0 ) ) - bc ) ( a ^ ( 2 ) + b ^ ( 2 ) ) ). ) Horizontal and vertical lines In the general equation of a line, ax + by + c = 0, a and b can not both be zero unless c is also zero, in which case the equation does not define a line. If a = 0 and b ≠ 0, the line is horizontal and has equation y = - c / b. The distance from ( x, y ) to this line is measured along a vertical line segment of length y - ( - c / b ) = by + c / b in accordance with the formula. Similarly, for vertical lines ( b = 0 ) the distance between the same point and the line is ax + c / a, as measured along a horizontal line segment. Line defined by two points If the line passes through two points P = ( x, y ) and P = ( x, y ) then the distance of ( x, y ) from the line is : distance ⁡ ( P 1, P 2, ( x 0, y 0 ) ) = ( y 2 − y 1 ) x 0 − ( x 2 − x 1 ) y 0 + x 2 y 1 − y 2 x 1 ( y 2 − y 1 ) 2 + ( x 2 − x 1 ) 2. ( displaystyle operatorname ( distance ) ( P_ ( 1 ), P_ ( 2 ), ( x_ ( 0 ), y_ ( 0 ) ) ) = ( \frac ( ( y_ ( 2 ) - y_ ( 1 ) ) x_ ( 0 ) - ( x_ ( 2 ) - x_ ( 1 ) ) y_ ( 0 ) + x_ ( 2 ) y_ ( 1 ) - y_ ( 2 ) x_ ( 1 ) ) ( sqrt ( ( y_ ( 2 ) - y_ ( 1 ) ) ^ ( 2 ) + ( x_ ( 2 ) - x_ ( 1 ) ) ^ ( 2 ) ) ) ). ) The denominator of this expression is the distance between P and P. The numerator is twice the area of the triangle with its vertices at the three points, ( x, y ), P and P. See : Area of a triangle # Using coordinates. The expression is equivalent to h = 2 A b ( \textstyle h = ( \frac ( 2A ) ( b ) ) ), which can be obtained by rearranging the standard formula for the area of a triangle : A = 1 2 b h ( \textstyle A = ( \frac ( 1 ) ( 2 ) ) bh ), where b is the length of a side, and h is the perpendicular height from the opposite vertex. Proofs An algebraic proof This proof is only valid if the line is neither vertical nor horizontal, that is, we assume that neither a nor b in the equation of the line is zero. 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 ). Let ( m, n ) be the point of intersection of the line ax + by + c = 0 and the line perpendicular to it which passes through the point ( x, y ). The line through these two points is perpendicular to the original line, so y 0 − n x 0 − m = b a. ( displaystyle ( \frac ( y_ ( 0 ) - n ) ( x_ ( 0 ) - m ) ) = ( \frac ( b ) ( a ) ). ) Thus, a ( y 0 − n ) − b ( x 0 − m ) = 0, ( displaystyle a ( y_ ( 0 ) - n ) - b ( x_ ( 0 ) - m ) = 0, ) and by squaring this equation we obtain : a 2 ( y 0 − n ) 2 + b 2 ( x 0 − m ) 2 = 2 a b ( y 0 − n ) ( x 0 − m ). ( displaystyle a ^ ( 2 ) ( y_ ( 0 ) - n ) ^ ( 2 ) + b ^ ( 2 ) ( x_ ( 0 ) - m ) ^ ( 2 ) = 2ab ( y_ ( 0 ) - n ) ( x_ ( 0 ) - m ). ) Now consider, ( a ( x 0 − m ) + b ( y 0 − n ) ) 2 = a 2 ( x 0 − m ) 2 + 2 a b ( y 0 − n ) ( x 0 − m ) + b 2 ( y 0 − n ) 2 = ( a 2 + b 2 ) ( ( x 0 − m ) 2 + ( y 0 − n ) 2 ) ( displaystyle ( a ( x_ ( 0 ) - m ) + b ( y_ ( 0 ) - n ) ) ^ ( 2 ) = a ^ ( 2 ) ( x_ ( 0 ) - m ) ^ ( 2 ) + 2ab ( y_ ( 0 ) - n ) ( x_ ( 0 ) - m ) + b ^ ( 2 ) ( y_ ( 0 ) - n ) ^ ( 2 ) = ( a ^ ( 2 ) + b ^ ( 2 ) ) ( ( x_ ( 0 ) - m ) ^ ( 2 ) + ( y_ ( 0 ) - n ) ^ ( 2 ) ) ) using the above squared equation. But we also have, ( a ( x 0 − m ) + b ( y 0 − n ) ) 2 = ( a x 0 + b y 0 − a m − b n ) 2 = ( a x 0 + b y 0 + c ) 2 ( displaystyle ( a ( x_ ( 0 ) - m ) + b ( y_ ( 0 ) - n ) ) ^ ( 2 ) = ( ax_ ( 0 ) + by_ ( 0 ) - am - bn ) ^ ( 2 ) = ( ax_ ( 0 ) + by_ ( 0 ) + c ) ^ ( 2 ) ) since ( m, n ) is on ax + by + c = 0. Thus, ( a 2 + b 2 ) ( ( x 0 − m ) 2 + ( y 0 − n ) 2 ) = ( a x 0 + b y 0 + c ) 2 ( displaystyle ( a ^ ( 2 ) + b ^ ( 2 ) ) ( ( x_ ( 0 ) - m ) ^ ( 2 ) + ( y_ ( 0 ) - n ) ^ ( 2 ) ) = ( ax_ ( 0 ) + by_ ( 0 ) + c ) ^ ( 2 ) ) and we obtain the length of the line segment determined by these two points, d = ( x 0 − m ) 2 + ( y 0 − n ) 2 = a x 0 + b y 0 + c a 2 + b 2. ( displaystyle d = ( sqrt ( ( x_ ( 0 ) - m ) ^ ( 2 ) + ( y_ ( 0 ) - n ) ^ ( 2 ) ) ) = ( \frac ( ax_ ( 0 ) + by_ ( 0 ) + c ) ( sqrt ( a ^ ( 2 ) + b ^ ( 2 ) ) ) ). ) A geometric proof Diagram for geometric proof This proof is valid only if the line is not horizontal or vertical. Drop a perpendicular from the point P with coordinates ( x, y ) 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 ). Corresponding sides of these triangles are in the same ratio, so : P R  ̄ P S  ̄ = T V  ̄ T U  ̄. ( displaystyle ( \frac ( ( overline ( PR ) ) ) ( ( overline ( PS ) ) ) ) = ( \frac ( ( overline ( TV ) ) ) ( ( overline ( TU ) ) ) ). ) If point S has coordinates ( x, m ) then PS = y - m and the distance from P to the line is : P R  ̄ = y 0 − m B A 2 + B 2. ( displaystyle ( overline ( PR ) ) = ( \frac ( y_ ( 0 ) - m B ) ( sqrt ( A ^ ( 2 ) + B ^ ( 2 ) ) ) ). ) Since S is on the line, we can find the value of m, m = − A x 0 − C B, ( displaystyle m = ( \frac ( - Ax_ ( 0 ) - C ) ( B ) ), ) and finally obtain : P R  ̄ = A x 0 + B y 0 + C A 2 + B 2. ( displaystyle ( overline ( PR ) ) = ( \frac ( Ax_ ( 0 ) + By_ ( 0 ) + C ) ( sqrt ( A ^ ( 2 ) + B ^ ( 2 ) ) ) ). ) A variation of this proof is to place V at P and compute the area of the triangle ∆ UVT two ways to obtain that D T U  ̄ = V U  ̄ V T  ̄ ( displaystyle D ( overline ( TU ) ) = ( overline ( VU ) ) ( overline ( VT ) ) ) where D is the altitude of ∆ UVT drawn to the hypoteneuse of ∆ UVT from P. The distance formula can then used to express T U  ̄ ( displaystyle ( overline ( TU ) ) ), V U  ̄ ( displaystyle ( overline ( VU ) ) ), and V T  ̄ ( displaystyle ( overline ( VT ) ) ) in terms of the coordinates of P and the coefficients of the equation of the line to get the indicated formula. A vector projection proof Let P be the point with coordinates ( x, y ) and let the given line have equation ax + by + c = 0. Also, let Q = ( x, y ) be any point on this line and n the vector ( a, b ) starting at point Q. 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 Q P → ( displaystyle ( overrightarrow ( QP ) ) ) on n. The length of this projection is given by : d = Q P → ⋅ n ∥ n ∥. ( displaystyle d = ( \frac ( ( overrightarrow ( QP ) ) cdot mathbf ( n ) ) ( mathbf ( n ) ) ). ) Now, Q P → = ( x 0 − x 1, y 0 − y 1 ), ( displaystyle ( overrightarrow ( QP ) ) = ( x_ ( 0 ) - x_ ( 1 ), y_ ( 0 ) - y_ ( 1 ) ), ) so Q P → ⋅ n = a ( x 0 − x 1 ) + b ( y 0 − y 1 ) ( displaystyle ( overrightarrow ( QP ) ) cdot mathbf ( n ) = a ( x_ ( 0 ) - x_ ( 1 ) ) + b ( y_ ( 0 ) - y_ ( 1 ) ) ) and ∥ n ∥ = a 2 + b 2, ( displaystyle mathbf ( n ) = ( sqrt ( a ^ ( 2 ) + b ^ ( 2 ) ) ), ) thus d = a ( x 0 − x 1 ) + b ( y 0 − y 1 ) a 2 + b 2. ( displaystyle d = ( \frac ( a ( x_ ( 0 ) - x_ ( 1 ) ) + b ( y_ ( 0 ) - y_ ( 1 ) ) ) ( sqrt ( a ^ ( 2 ) + b ^ ( 2 ) ) ) ). ) Since Q is a point on the line, c = − a x 1 − b y 1 ( displaystyle c = - ax_ ( 1 ) - by_ ( 1 ) ), and so, d = a x 0 + b y 0 + c a 2 + b 2. ( displaystyle d = ( \frac ( ax_ ( 0 ) + by_ ( 0 ) + c ) ( sqrt ( a ^ ( 2 ) + b ^ ( 2 ) ) ) ). ) 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 P is given with coordinates ( x 0, y 0 ( displaystyle x_ ( 0 ), y_ ( 0 ) ) ). The equation of a line is given by y = m x + k ( displaystyle y = mx + k ). The equation of the normal of that line which passes through the point P is given y = x 0 − x m + y 0 ( displaystyle y = ( \frac ( x_ ( 0 ) - x ) ( m ) ) + y_ ( 0 ) ). The point at which these two lines intersect is the closest point on the original line to the point P. Hence : m x + k = x 0 − x m + y 0. ( displaystyle mx + k = ( \frac ( x_ ( 0 ) - x ) ( m ) ) + y_ ( 0 ). ) We can solve this equation for x, x = x 0 + m y 0 − m k m 2 + 1. ( displaystyle x = ( \frac ( x_ ( 0 ) + my_ ( 0 ) - mk ) ( m ^ ( 2 ) + 1 ) ). ) The y coordinate of the point of intersection can be found by substituting this value of x into the equation of the original line, y = m ( x 0 + m y 0 − m k ) m 2 + 1 + k. ( displaystyle y = m ( \frac ( ( x_ ( 0 ) + my_ ( 0 ) - mk ) ) ( m ^ ( 2 ) + 1 ) ) + k. ) Using the equation for finding the distance between 2 points, d = ( X 2 − X 1 ) 2 + ( Y 2 − Y 1 ) 2 ( displaystyle d = ( sqrt ( ( X_ ( 2 ) - X_ ( 1 ) ) ^ ( 2 ) + ( Y_ ( 2 ) - Y_ ( 1 ) ) ^ ( 2 ) ) ) ), we can deduce that the formula to find the shortest distance between a line and a point is the following : d = ( x 0 + m y 0 − m k m 2 + 1 − x 0 ) 2 + ( m x 0 + m y 0 − m k m 2 + 1 + k − y 0 ) 2 = k + m x 0 − y 0 1 + m 2. ( displaystyle d = ( sqrt ( left ( ( ( \frac ( x_ ( 0 ) + my_ ( 0 ) - mk ) ( m ^ ( 2 ) + 1 ) ) - x_ ( 0 ) ) \right ) ^ ( 2 ) + left ( ( m ( \frac ( x_ ( 0 ) + my_ ( 0 ) - mk ) ( m ^ ( 2 ) + 1 ) ) + k - y_ ( 0 ) ) \right ) ^ ( 2 ) ) ) = ( \frac ( k + mx_ ( 0 ) - y_ ( 0 ) ) ( sqrt ( 1 + m ^ ( 2 ) ) ) ). ) 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. Vector formulation Illustration of the vector formulation. The equation of a line can be given in vector form : x = a + t n ( displaystyle mathbf ( x ) = mathbf ( a ) + t mathbf ( n ) ) 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 t varies, x gives the locus of the line. The distance of an arbitrary point p to this line is given by distance ⁡ ( x = a + t n, p ) = ∥ ( a − p ) − ( ( a − p ) ⋅ n ) n ∥. ( displaystyle 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 formula can be derived as follows : a − p ( displaystyle mathbf ( a ) - mathbf ( p ) ) is a vector from p to the point a on the line. Then ( a − p ) ⋅ n ( displaystyle ( mathbf ( a ) - mathbf ( p ) ) cdot mathbf ( n ) ) is the projected length onto the line and so ( ( a − p ) ⋅ n ) n ( displaystyle ( ( mathbf ( a ) - mathbf ( p ) ) cdot mathbf ( n ) ) mathbf ( n ) ) is a vector that is the projection of a − p ( displaystyle mathbf ( a ) - mathbf ( p ) ) onto the line. Thus ( a − p ) − ( ( a − p ) ⋅ n ) n ( displaystyle ( mathbf ( a ) - mathbf ( p ) ) - ( ( mathbf ( a ) - mathbf ( p ) ) cdot mathbf ( n ) ) mathbf ( n ) ) is the component of a − p ( displaystyle mathbf ( a ) - mathbf ( p ) ) perpendicular to the line. The distance from the point to the line is then just the norm of that vector. This more general formula is not restricted to two dimensions. Another vector formulation If the vector space is orthonormal and if the line ( l ) goes through point A and has a direction vector u → ( displaystyle ( \vec ( u ) ) ), the distance between point P and line ( l ) is d ( P, ( l ) ) = ∥ A P → × u → ∥ ∥ u → ∥ ( displaystyle d ( mathrm ( P ), ( l ) ) = ( \frac ( left ( overrightarrow ( mathrm ( AP ) ) ) \times ( \vec ( u ) ) \right ) ( ( \vec ( u ) ) ) ) ) where A P → × u → ( displaystyle ( overrightarrow ( mathrm ( AP ) ) ) \times ( \vec ( u ) ) ) is the cross product of the vectors A P → ( displaystyle ( overrightarrow ( mathrm ( AP ) ) ) ) and u → ( displaystyle ( \vec ( u ) ) ) and where ∥ u → ∥ ( displaystyle ( \vec ( u ) ) ) is the vector norm of u → ( displaystyle ( \vec ( u ) ) ). Note that cross products only exist in dimensions 3 and 7. See also Hesse normal form Line - line intersection Distance between two lines Distance from a point to a plane Skew lines # Distance Notes Jump up ^ Larson & Hostetler 2007, p. 452 Jump up ^ Spain 2007 Jump up ^ Larson & Hostetler 2007, p. 522 Jump up ^ Between Certainty and Uncertainty : Statistics and Probability in Five Units With Notes on Historical Origins and Illustrative Numerical Examples Jump up ^ Ballantine & Jerbert 1952 do not mention this restriction in their article Jump up ^ If the two triangles are on opposite sides of the line, these angles are congruent because they are alternate interior angles. Jump up ^ Ballantine & Jerbert 1952 Jump up ^ Anton 1994, pp. 138 - 9 Jump up ^ Larson & Hostetler 2007, p. 522 Jump up ^ Sunday, Dan. `` Lines and Distance of a Point to a Line ''. softSurfer. Retrieved 6 December 2013. References Anton, Howard ( 1994 ), Elementary Linear Algebra ( 7th ed. ), John Wiley & Sons, ISBN 0 - 471 - 58742 - 7 Ballantine, J.P. ; Jerbert, A.R. ( 1952 ), `` Distance from a line or plane to a point '', American Mathematical Monthly, 59 : 242 -- 243, doi : 10.2307 / 2306514 Larson, Ron ; Hostetler, Robert ( 2007 ), Precalculus : A Concise Course, Houghton Mifflin Co., ISBN 0 - 618 - 62719 - 7 Spain, Barry ( 2007 ) ( 1957 ), Analytical Conics, Dover Publications, ISBN 0 - 486 - 45773 - 7 Further reading Deza, Michel Marie ; Deza, Elena ( 2013 ), Encyclopedia of Distances ( 2nd ed. ), Springer, p. 86, ISBN 9783642309588 Retrieved from `` https://en.wikipedia.org/w/index.php?title=Distance_from_a_point_to_a_line&oldid=805845451 '' Categories : Euclidean geometry Vectors ( mathematics and physics ) Hidden categories : All articles with unsourced statements Articles with unsourced statements from April 2015 Talk Contents About Wikipedia Català Español Français Italiano עברית ភាសា ខ្មែរ Polski Русский தமிழ் Українська Edit links This page was last edited on 18 October 2017, at 00 : 30. Text is available under the Creative Commons Attribution - ShareAlike License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia ® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization. About Wikipedia

Question: directed distance from a line to a point
Answer: perpendicular distance