TOPICS
Search

Point-Line Distance--2-Dimensional


PointLineDistance2D

The equation of a line ax+by+c=0 in slope-intercept form is given by

 y=-a/bx-c/b,
(1)

so the line has slope -a/b. Now consider the distance from a point (x_0,y_0) to the line. Points on the line have the vector coordinates

 [x; -a/bx-c/b]=[0; -c/b]-1/b[-b; a]x.
(2)

Therefore, the vector

 [-b; a]
(3)

is parallel to the line, and the vector

 v=[a; b]
(4)

is perpendicular to it. Now, a vector from the point to the line is given by

 r=[x-x_0; y-y_0].
(5)

Projecting r onto v,

d=|proj_(v)r|
(6)
=(|v·r|)/(|v|)
(7)
=|v^^·r|
(8)
=(|a(x-x_0)+b(y-y_0)|)/(sqrt(a^2+b^2))
(9)
=(|ax+by-ax_0-by_0|)/(sqrt(a^2+b^2))
(10)
=(|ax_0+by_0+c|)/(sqrt(a^2+b^2)).
(11)
PointLineDistance2DVec

If the line is specified by two points x_1=(x_1,y_1) and x_2=(x_2,y_2), then a vector perpendicular to the line is given by

 v=[y_2-y_1; -(x_2-x_1)].
(12)

Let r be a vector from the point x_0=(x_0,y_0) to the first point on the line

 r=[x_1-x_0; y_1-y_0],
(13)

then the distance from (x_0,y_0) to the line is again given by projecting r onto v, giving

 d=|v^^·r|=(|(x_2-x_1)(y_1-y_0)-(x_1-x_0)(y_2-y_1)|)/(sqrt((x_2-x_1)^2+(y_2-y_1)^2)).
(14)

As it must, this formula corresponds to the distance in the three-dimensional case

 d=(|(x_2-x_1)x(x_1-x_0)|)/(|x_2-x_1|)
(15)

with all vectors having zero z-components, and can be written in the slightly more concise form

 d=(|det(x_2-x_1  x_1-x_0)|)/(|x_2-x_1|),
(16)

where det(A) denotes a determinant.

The distance between a point with exact trilinear coordinates (alpha^',beta^',gamma^') and a line lalpha+mbeta+ngamma=0 is

 d=(|lalpha^'+mbeta^'+ngamma^'|)/(sqrt(l^2+m^2+n^2-2mncosA-2nlcosB-2lmcosC))
(17)

(Kimberling 1998, p. 31).


See also

Collinear, Point-Line Distance--3-Dimensional

Explore with Wolfram|Alpha

References

Kimberling, C. "Triangle Centers and Central Triangles." Congr. Numer. 129, 1-295, 1998.

Cite this as:

Weisstein, Eric W. "Point-Line Distance--2-Dimensional." From MathWorld--A Wolfram Web Resource. https://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html

Subject classifications