info prev up next book cdrom email home

Point-Line Distance--2-D

Given a line $ax+by+c = 0$ and a point $(x_0,y_0$), in slope-intercept form, the equation of the line is

\begin{displaymath}
y = - {a\over b} x - {c\over b},
\end{displaymath} (1)

so the line has Slope $-a/b$. Points on the line have the vector coordinates
\begin{displaymath}
\left[{\matrix{x\cr -{a\over b}x-{c\over d}\cr}}\right] = \l...
...r d}\cr}}\right]-{1\over b}\left[{\matrix{-b\cr a\cr}}\right].
\end{displaymath} (2)

Therefore, the Vector
\begin{displaymath}
\left[{\matrix{-b\cr a\cr}}\right]
\end{displaymath} (3)

is Parallel to the line, and the Vector
\begin{displaymath}
{\bf v} =\left[{\matrix{a\cr b\cr}}\right]
\end{displaymath} (4)

is Perpendicular to it. Now, a Vector from the point to the line is given by
\begin{displaymath}
{\bf r} = \left[{\matrix{x-x_0\cr y-y_0\cr}}\right].
\end{displaymath} (5)

Projecting ${\bf r}$ onto ${\bf v}$,
$\displaystyle \vert{\rm proj}_{\bf v}{\bf r}\vert$ $\textstyle =$ $\displaystyle {\vert{\bf v}\cdot {\bf r}\vert\over \vert{\bf v}\vert} = \vert{\hat {\bf v}\cdot{\bf r}}\vert
= {\vert a(x-x_0)+b(y-y_0)\vert\over \sqrt{a^2+b^2}}$  
  $\textstyle =$ $\displaystyle {\vert ax+by-ax_0-by_0\vert\over \sqrt{a^2+b^2}}$  
  $\textstyle =$ $\displaystyle {\vert ax_0+by_0+c\vert\over \sqrt{a^2+b^2}}.$ (6)

If the line is represented by the endpoints of a Vector $(x_1, y_1)$ and $(x_2, y_2)$, then the Perpendicular Vector is
\begin{displaymath}
\bf v= \left[{\matrix{y_2-y_1\cr -(x_2-x_1)\cr}}\right]
\end{displaymath} (7)


\begin{displaymath}
\hat{\bf v}= {1\over s}\left[{\matrix{y_2-y_1\cr -(x_2-x_1)\cr}}\right],
\end{displaymath} (8)

where
\begin{displaymath}
s=\vert{\bf v}\vert=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2},
\end{displaymath} (9)

so the distance is
\begin{displaymath}
d=\vert{\hat {\bf v}\cdot{\bf r}}\vert ={\vert(y_2-y_1)(x_0-x_1)-(x_2-x_1)(y_0-y_1)\vert\over s}.
\end{displaymath} (10)

The distance from a point ($x_1$,$y_1$) to the line $y=a+bx$ can be computed using Vector algebra. Let ${\bf L}$ be a Vector in the same direction as the line

$\displaystyle {\bf L}$ $\textstyle =$ $\displaystyle \left[\begin{array}{c}x\\  a+bx\end{array}\right]-\left[\begin{array}{c}0\\  a\end{array}\right]=\left[\begin{array}{c}x\\  bx\end{array}\right]$ (11)
$\displaystyle \hat {\bf L}$ $\textstyle =$ $\displaystyle {1\over \sqrt{b^2+1}} \left[\begin{array}{c}1\\  b\end{array}\right].$ (12)

A given point on the line is
\begin{displaymath}
{\bf x}=\left[{\matrix{x_1\cr y_1\cr}}\right]-\left[{\matrix{0\cr -a\cr}}\right] = \left[{\matrix{x_1\cr y_1-a\cr}}\right],
\end{displaymath} (13)

so the point-line distance is
$\displaystyle {\bf r}$ $\textstyle =$ $\displaystyle ({\bf x}\cdot \hat{\bf L})\hat{\bf L}-{\bf x}$  
  $\textstyle =$ $\displaystyle {1\over 1+b^2}\left({\left[\begin{array}{c}x_1\\  y_1-a\end{array...
...nd{array}\right] -\left[\begin{array}{c}x_1\\  y_1-a\end{array}\right]\nonumber$  
  $\textstyle =$ $\displaystyle {x_1+b(y_1-a)\over 1+b^2}\left[\begin{array}{c}1\\  b\end{array}\right]-\left[\begin{array}{c}x_1\\  y_1-a\end{array}\right]$  
  $\textstyle =$ $\displaystyle {1\over 1+b^2}\left[\begin{array}{c}b(y_1-a)-b^2x_1\\  bx_1+b^2y_1-ab^2-y_1+a-b^2y_1+ab^2\end{array}\right]$  
  $\textstyle =$ $\displaystyle {1\over 1+b^2} \left[\begin{array}{c}b[(y_1-a)-bx_1]\\  -[(y_1-a)-bx_1]\end{array}\right]$  
  $\textstyle =$ $\displaystyle {y_1-(a+bx_1)\over 1+b^2} \left[\begin{array}{c}b\\  -1\end{array}\right].$ (14)

Therefore,
\begin{displaymath}
d = \vert{\bf r}\vert = {\vert y_1-(a+bx_1)\vert\over 1+b^2} \sqrt{1+b^2} = {\vert y_1-(a+bx_1)\vert\over\sqrt{1+b^2}}.
\end{displaymath} (15)

This result can also be obtained much more simply by noting that the Perpendicular distance is just $\cos\theta$ times the vertical distance $\vert y_1-(a+bx_1)\vert$. But the Slope $b$ is just $\tan\theta$, so
\begin{displaymath}
\sin^2\theta +\cos ^2\theta =1 \Rightarrow \tan^2\theta +1={1\over\cos^2\theta},
\end{displaymath} (16)

and
\begin{displaymath}
\cos\theta={1\over \sqrt{1+\tan^2\theta}}={1\over\sqrt{1+b^2}}.
\end{displaymath} (17)

The Perpendicular distance is then
\begin{displaymath}
d={\vert y_1-(a+bx_1)\vert\over\sqrt{1+b^2}},
\end{displaymath} (18)

the same result as before.

See also Line, Point, Point-Line Distance--3-D



info prev up next book cdrom email home

© 1996-9 Eric W. Weisstein
1999-05-25