Distance from a point to a line: Difference between revisions

Content deleted Content added
A geometric proof: we have too many proofs already; we don't need unsourced variations
Sebbes333 (talk | contribs)
@Wcherowi You are supposed to IMPROVE the page! Not just "undo" other peoples work! That is NOT an improvement! Do better!
Line 1:
InThe [[Euclidean'''distance''' geometry]], the(or '''perpendicular distance''') '''from a point to a line''' is the shortest [[Euclidean distance|distance]] from a givenfixed [[Point (geometry)|point]] to any point on ana fixed infinite [[Line (mathematics)|straight line]]. It is thein [[perpendicularEuclidean distancegeometry]]. ofIt the point to the line,is the length of the [[line segment]] which joins the point to nearestthe pointline onand is [[perpendicular]] to the line. The [[algebraic expression]]formula for calculating it can be derived and expressed in several ways.
{{Short description|Problem in coordinate geometry}}
In [[Euclidean geometry]], the '''distance from a point to a line''' is the shortest [[Euclidean distance|distance]] from a given [[Point (geometry)|point]] to any point on an infinite [[Line (mathematics)|straight line]]. It is the [[perpendicular distance]] of the point to the line, the length of the [[line segment]] which joins the point to nearest point on the line. The [[algebraic expression]] 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==
<!--''This '''picture''' is a stub. You can help Wikipedia by improving it.''
[[File:PointToLineDistance v2.png|thumb|''This '''picture''' is a stub, help improve it.''. It tries to explain the roles of the values in the formula. Note: values are NOT to scale. Cyan line represents the formula to the left.]]
 
== =Line defined by an equation ===
[[File:PointToLineDistance.png|PointToLineDistance]] -->
In the case of a line in the plane given by the equation {{mathnowrap|1=''ax'' + ''by'' + ''c'' = 0,}}, where {{mvar|''a}}'', {{mvar|''b}}'' and {{mvar|''c}}'' are [[real number|real]] constants with {{mvar|''a}}'' and {{mvar|''b}}'' not both zero, the distance from the line to a point {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}} is<ref>{{harvnb|Larson|Hostetler|2007|loc=p. 452}}</ref><ref>{{harvnb|Spain|2007}}</ref>{{rp|p.14}}
 
== Line defined by an equation ==
In the case of a line in the plane given by the equation {{math|1=''ax'' + ''by'' + ''c'' = 0}}, where {{mvar|a}}, {{mvar|b}} and {{mvar|c}} are [[real number|real]] constants with {{mvar|a}} and {{mvar|b}} not both zero, the distance from the line to a point {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}} is<ref>{{harvnb|Larson|Hostetler|2007|loc=p. 452}}</ref><ref>{{harvnb|Spain|2007}}</ref>{{rp|p.14}}
 
:<math>\operatorname{distance}(ax+by+c=0, (x_0, y_0)) = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}. </math>
 
The point on this line which is closest to {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}} has coordinates:<ref name="Larson 2007 loc=p. 522">{{harvnb|Larson|Hostetler|2007|loc=p. 522}}</ref>
:<math>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}.</math>
 
'''Horizontal and vertical lines'''
 
In the general equation of a line, {{math|1=''ax'' + ''by'' + ''c'' = 0}}, {{mvar|''a}}'' and {{mvar|''b}}'' cannot both be zero unless {{mvar|''c}}'' is also zero, in which case the equation does not define a line. If {{math|1=''a'' &nbsp;= &nbsp;0}} and {{math|''b'' &nbsp;{{math| 0}}&nbsp;0, the line is horizontal and has equation {{math|1=''y'' = −{{sfrac|-''c''|/''b''}}}}. The distance from {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}} to this line is measured along a vertical line segment of length {{math|1={{!}}''y''<sub>0</sub> - (−{{sfrac|-''c''|/''b''}}){{!}}| = {{sfrac|{{!}}''by''<sub>0</sub> + ''c''{{!}}|{{!}} / |''b''{{!}}}}}}| in accordance with the formula. Similarly, for vertical lines (''b'' = 0) the distance between the same point and the line is {{math|1={{sfrac|{{!}}''ax''<sub>0</sub> + ''c''{{!}}|{{!}} / |''a''{{!}}}} }}|, as measured along a horizontal line segment.
 
== Line defined by two points ==
If the line passes through two points {{math|1=''P''<sub>1</sub> = (''x''<sub>1</sub>, ''y''<sub>1</sub>)}} and {{math|1=''P''<sub>2</sub> = (''x<sub>2</sub>'', ''y<sub>2</sub>'')}} then the distance of {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}} from the line is:<ref name=GEO />
:<math>\operatorname{distance}(P_1, P_2, (x_0, y_0)) = \frac{|(x_2-x_1)(y_0-y_1)-(x_0-x_1)(y_2-y_1)|}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}. </math>
 
== =Line defined by two points ===
The denominator of this expression is the distance between {{math|''P''<sub>1</sub>}} and {{math|''P''<sub>2</sub>}}. The numerator is twice the area of the triangle with its vertices at the three points, {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}}, {{math|''P''<sub>1</sub>}} and {{math|''P''<sub>2</sub>}}. See: {{slink|Area of a triangle|Using coordinates}}. The expression is equivalent to {{math|1=''h'' = {{sfrac|2''A''|''b''}}}}, which can be obtained by rearranging the standard formula for the area of a triangle: {{math|1=''A'' = {{sfrac|1|2}} ''bh''}}, where {{mvar|b}} is the length of a side, and {{mvar|h}} is the perpendicular height from the opposite vertex.
If the line passes through two points {{math|1=''P''<sub>1</sub> = (''x''<sub>1</sub>, ''y''<sub>1</sub>)}} and {{math|1=''P''<sub>2</sub> = (''x<sub>2</sub>'', ''y<sub>2</sub>'')}} then the distance of {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}} from the line is:<ref name=GEO />
:<math>\operatorname{distance}(P_1, P_2, (x_0, y_0)) = \frac{|(x_2-x_1)(y_0y_2-y_1)x_0-(x_0x_2-x_1)(y_0+x_2 y_1-y_2-y_1) x_1|}{\sqrt{(x_2y_2-x_1y_1)^2+(y_2x_2-y_1x_1)^2}}. </math>
 
The denominator of this expression is the distance between {{math|''P''<sub>1</sub>}}'' and {{math|''P''<sub>2</sub>}}''. The numerator is twice the area of the triangle with its vertices at the three points, {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}}, {{math|''P''<sub>1</sub>}}'' and {{math|''P''<sub>2</sub>}}''. See: {{slink|Area of a triangle|Using coordinates}}. The expression is equivalent to {{<math|1 display=''"inline">h'' = \frac{2A}{sfrac|2''A''|''b''}}}}</math>, which can be obtained by rearranging the standard formula for the area of a triangle: {{<math|1 display=''"inline">A'' = \frac{1}{sfrac|1|2}} ''bh''}}</math>, where {{mvar|''b}}'' is the length of a side, and {{mvar|''h}}'' is the perpendicular height from the opposite vertex.
== Line defined by point and angle ==
If the line passes through the point {{math|1=''P'' = (''P''<sub>x</sub>, ''P''<sub>y</sub>)}} with angle {{math|''θ''}}, then the distance of some point {{math|(''x''<sub>0</sub>, ''y''<sub>0</sub>)}} to the line is
:<math>\operatorname{distance}(P, \theta, (x_0, y_0)) = |\cos(\theta)(P_y-y_0) -\sin(\theta)(P_x-x_0)| </math>
 
==Proofs==
 
===An algebraic proof===
This proof is valid only if the line is neither vertical nor horizontal, that is, we assume that neither {{mvar|''a}}'' nor {{mvar|''b}}'' in the equation of the line is zero.
 
The line with equation {{math|1=''ax'' + ''by'' + ''c'' = 0}} has slope {{math|−-''a''/''b''}}, so any line perpendicular to it will have slope {{math|''b''/''a''}} (the negative reciprocal). Let {{math|(''m'', ''n'')}} be the point of intersection of the line {{math|1=''ax'' + ''by'' + ''c'' = 0}} and the line perpendicular to it which passes through the point ({{math|''x''<sub>0</sub>}}, {{math|''y''<sub>0</sub>}}). The line through these two points is perpendicular to the original line, so
:<math>\frac{y_0 - n}{x_0 - m}=\frac{b}{a}.</math>
Thus,
Line 43 ⟶ 36:
 
Now consider,
:<math> (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)</math>
:<math>
\begin{align}
(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 \\
& = \left(a^2 + b^2\right) \left((x_0 - m)^2 + (y_0 - n)^2\right)
\end{align}
</math>
using the above squared equation. But we also have,
:<math> (a(x_0 - m) + b(y_0 - n))^2 = (ax_0 + by_0 - am - bn )^2 = (ax_0 + by_0 + c)^2</math>
since {{math|(''m'', ''n'')}} is on {{math|1=''ax'' + ''by'' + ''c'' = 0}}.
Thus,
:<math>\left(a^2 + b^2\right) \left((x_0 - m)^2 + (y_0 - n)^2\right) = (ax_0 + by_0 + c)^2 </math>
and we obtain the length of the line segment determined by these two points,
:<math>d=\sqrt{(x_0 - m)^2+(y_0 - n)^2} = \frac{|ax_0+ by_0 +c|}{\sqrt{a^2+b^2}}.</math><ref>Between Certainty and Uncertainty: Statistics and Probability in Five Units With Notes on Historical Origins and Illustrative Numerical Examples</ref>
 
===A geometric proof===
Line 72 ⟶ 60:
and finally obtain:<ref>{{harvnb|Ballantine|Jerbert|1952}}</ref>
:<math> |\overline{PR}| = \frac{|Ax_0 + By_0 + C|}{\sqrt{A^2 + B^2}}.</math>
 
A variation of this proof is to place V at P and compute the area of the triangle ∆''UVT'' two ways to obtain that <math>D|\overline{TU}| = |\overline{VU}||\overline{VT}|</math>
where D is the altitude of ∆''UVT'' drawn to the hypoteneuse of ∆''UVT'' from ''P''. The distance formula can then used to express <math>|\overline{TU}|</math>, <math>|\overline{VU}|</math>, and <math>|\overline{VT}|</math>in terms of the coordinates of P and the coefficients of the equation of the line to get the indicated formula.{{citation needed|date=April 2015}}
 
===A vector projection proof===
Line 84 ⟶ 75:
Since ''Q'' is a point on the line, <math>c = -ax_1 - by_1</math>, and so,<ref>{{harvnb|Anton|1994|loc=pp. 138-9}}</ref>
:<math> d = \frac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}}.</math>
Although the distance is given as a modulus, the sign can be useful to determine which side of the line the point is on, in a sense determined by the direction of normal vector (a,b)
 
== 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 beis not vertical or horizontal.
 
The point P is given with coordinates (<math>x_0, y_0</math>).
Line 103 ⟶ 93:
:<math>d=\sqrt{ \left( {\frac{x_0 + m y_0-mk}{m^2+1}-x_0 } \right) ^2 + \left( {m\frac{x_0+m y_0-mk}{m^2+1}+k-y_0 }\right) ^2 } = \frac{|k + m x_0 - y_0|}\sqrt{1 + m^2} .</math>
 
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.<ref name=">{{harvnb|Larson |Hostetler|2007 |loc=p. 522"}}</ref>
 
==Vector formulation==
Line 112 ⟶ 102:
: <math> \mathbf{x} = \mathbf{a} + t\mathbf{n}</math>
 
Here {{math|'''a'''}} is the position of a point on the line, and {{math|'''n'''}} is a [[unit vector]] in the direction of the line. Then as scalar ''t'' varies, {{math|'''x'''}} gives the [[locus (mathematics)|locus]] of the line.
 
The distance of an arbitrary point {{math|'''p'''}} to this line is given by
 
: <math>\operatorname{distance}(\mathbf{x} = \mathbf{a} + t\mathbf{n}, \mathbf{p}) = \| (\mathbf{pa}-\mathbf{ap}) - ((\mathbf{pa}-\mathbf{ap}) \cdot \mathbf{n})\mathbf{n} \|. </math>
 
This formula can be derived as follows: <math>\mathbf{pa}-\mathbf{ap}</math> is a vector from {{math|'''ap'''}} to the point {{math|'''pa'''}} on the line. Then <math>(\mathbf{pa} - \mathbf{ap}) \cdot \mathbf{n}</math> is the projected length onto the line and so
:<math>\mathbf{a} + ((\mathbf{pa} - \mathbf{ap}) \cdot \mathbf{n})\mathbf{n}</math>
is a vector that is the [[projection (linear algebra)|projection]] of <math>\mathbf{pa}-\mathbf{ap}</math> onto the line and represents the point on the line closest to <math>\mathbf{p}</math>. Thus
:<math>(\mathbf{pa}-\mathbf{ap}) - ((\mathbf{pa}-\mathbf{ap}) \cdot \mathbf{n})\mathbf{n}</math>
is the component of <math>\mathbf{pa}-\mathbf{ap}</math> perpendicular to the line. The distance from the point to the line is then just the [[norm (mathematics)|norm]] of that vector.<ref name=GEO>{{cite web|last=Sunday|first=Dan|title=Lines and Distance of a Point to a Line|url=httpshttp://geomalgorithms.com/a02-_lines.html|publisher=softSurfer|url-statusaccessdate=dead|archive-url=https://web.archive.org/web/20210507021429/https://geomalgorithms.com/a02-_lines.html|archive-date=2021-05-076 December 2013}}</ref> This more general formula is not restricted to two dimensions.
 
== Another vector formulation ==
 
If the vector space is [[orthonormality|orthonormal]] and if the line (''l'' ) goes through point {{math|'''a'''}}A and has a [[Euclidean vector|direction vector]] {{<math|'''n'''}}>\vec u</math>, the distance between point {{math|P and line (''l'p'''}} and the line) is<ref>{{Cite web|last=Weisstein|first=Eric W.|title=Point-Line Distance--3-Dimensional
: <math>d(\mathrm{P}, (l))= \frac{\left\|\overrightarrow{\mathrm{AP}} \times\vec u\right\|}{\|\vec u\|}</math>
|url=https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html|access-date=2021-06-06|website=mathworld.wolfram.com|language=en}}</ref>
where <math>\overrightarrow{\mathrm{AP}} \times\vec u</math> is the [[cross product]] of the vectors <math>\overrightarrow{\mathrm{AP}}</math> and <math>\vec u</math> and where <math>\|\vec u\|</math> is the vector norm of <math>\vec u</math>.
 
: <math>\operatorname{distance}(\mathbf{x} = \mathbf{a} + t\mathbf{n}, \mathbf{p}) = \frac{\left\|(\mathbf{p}-\mathbf{a}) \times \mathbf{n}\right\|}{\|\mathbf{n}\|}.</math>
 
Note that cross products only exist in dimensions 3 and 7.
Line 145 ⟶ 134:
==References==
* {{citation|first=Howard|last=Anton|title=Elementary Linear Algebra|edition=7th|year=1994|publisher=John Wiley & Sons|isbn=0-471-58742-7}}
* {{citation|first1=J.P.|last1=Ballantine|first2=A.R.|last2=Jerbert|year=1952|volume=59|title=Distance from a line or plane to a point|journal=American Mathematical Monthly|issue=4|pages=242–243|doi=10.2307/2306514|jstor=2306514}}
* {{citation|first1=Ron|last1=Larson|first2=Robert|last2=Hostetler|title=Precalculus: A Concise Course|year=2007|publisher=Houghton Mifflin Co.|isbn=978-0-618-62719-67|url-access=registration|url=https://archive.org/details/precalculusconci00lars}}
* {{citation|first=Barry|last=Spain|title=Analytical Conics|year=2007|orig-yearorigyear=1957|publisher=Dover Publications|isbn=978-0-486-45773-47}}
* {{cite web|url=https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html|title=Point-Line Distance--3-Dimensional|last=Weisstein|first=Eric W.|author-link=Eric W. Weisstein|publisher=[[MathWorld]]}}
 
==Further reading==
*{{citation|title=Encyclopedia of Distances|first1=Michel Marie|last1=Deza|author1-link=Michel Deza|first2=Elena|last2=Deza|author2-link=Elena Deza|edition=2nd|publisher=Springer|year=2013|isbn=9783642309588|page=86|url=https://books.google.com/books?id=QxX2CX5OVMsC&pg=PA86}}
 
[[Category:Euclidean geometry]]