# Distance between point and line

The distance between a point \(P\) and a line \(L\) is the shortest distance between \(P\) and \(L\); it is the minimum length required to move from point \( P \) to a point on \( L \).

In fact, this path of minimum length can be shown to be a line segment perpendicular to \( L \).

The distance \(d\) can then defined as the length of the line segment that has \(P\) as an endpoint and is perpendicular to \(L\).

## Definition

For a point and a line (or in the third dimension, a plane), you could technically draw an infinite number of lines between the point and line or point and plane. So, which one gives you the "correct" distance between the point/line or point/plane? When we say distance, we mean the shortest possible distance from the point to the line/plane, which happens to be when the distance line through the point is also perpendicular to the line/plane.

But why is the shortest line segment perpendicular?

This is because the longest side in a right triangle is the hypotenuse. If we draw the foot of the perpendicular from the point to the line, and draw any other segment joining the point to the line, this segment will always be the hypotenuse of the right triangle formed.
**(add diagram for clarity - Ameya)**

What is the distance between point \(P\) and line \(L\) in the diagram above?

Each length of the line segments connecting the point and the line differs, but by definition the distance between point and line is the length of the line segment that is perpendicular to \(L\). In other words, the shortest distance between them, hence the answer is \(5\).

## Formula

The distance between point \(P(x_0,y_0)\) and line \(L:ax+by+c=0\) is

\[\large d = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}\]

Let's have a generic line \(ax + by + c = 0\) named \(L\). This line has slope \(-\dfrac{a}{b}\). Let's also have a generic point \(P(x_o, y_o)\). The distance between the line \(L\) and the point \(P\) can be represented by another line, perpendicular to \(L\); let's call it \(T\). \(T\) will have slope \(\dfrac{b}{a},\) since it's perpendicular to \(L\). Now, to find the distance between the point \(P\) and the line \(L\) we can use a little geometry trick and have another line, parallel to \(L\), that passes through \(P\): let's call it \(S\). Likewise, we can have another line, this time parallel to \(T\), that passes through the origin \((0,0)\); let's call it \(R\).

Now that drawing time's over, it's time to work.

First off, since \(S\) passes through \(P\) and has the same slope as \(L\), its equation is

\[y − y_0 = -\dfrac{a}{b}(x − x_0) \rightarrow y = \dfrac{-ax + ax_0 + by_0}{b}\]

The line \(R\) has equation

\[ y = \dfrac{b}{a}x\]

So, line \(S\) intersects with line \(R\) when

\[ \frac{b}{a}x = \dfrac{-ax + ax_0 + by_0}{b} \rightarrow x = \dfrac{a(ax_0 + by_0)}{a^2 + b^2} \]

Substituting back into \(R\)'s equation, we find that the intersection point between \(S\) and \(R\) is

\[ P_1 \left( \dfrac{a(ax_0 + by_0)}{a^2 + b^2} , \dfrac{b(ax_0 + by_0)}{a^2 + b^2} \right) \]

Now let's put that aside for a moment and let's look when the lines \(L\) and \(R\) intersect. This occurs when both \( y = \dfrac{b}{a}x \) and \( ax + by + c = 0 \ \ \rightarrow \ \ y = -\dfrac{ax + c}{b} \), are true. Solving this system of two equations for \(x\):

\[-\dfrac{ax + c}{b} = \dfrac{b}{a}x \ \ \rightarrow \ \ x = -\dfrac{ac}{a^2+b^2}\]

Using \(x\) to solve for \(y\):

\[y = \dfrac{b}{a}\left(-\dfrac{ac}{a^2 + b^2}\right) = -\dfrac{bc}{a^2 + b^2} \]

So the point of intersection of \(L\) and \(R\) is \[P_2 \left( - \ \dfrac{ac}{a^2 + b^2} , - \ \dfrac{bc}{a^2 + b^2} \right) \]

Now, using the distance formula \(d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2} \) we can tell the distance between \(P_1\) and \(P_2\):

\[ d = \sqrt{ \left( - \ \dfrac{ac}{a^2 + b^2} - \dfrac{a(ax_0 + by_0)}{a^2 + b^2} \right)^2 + \left( - \ \dfrac{bc}{a^2 + b^2} - \dfrac{b(ax_0 + by_0)}{a^2 + b^2} \right)^2 } \]

\[ = \sqrt{ \dfrac{[-a(ax_0 + by_0 + c)]^2 + [-b(ax_0 + by_0 + c)]^2}{(a^2+b^2)^2} } \]

\[ = \sqrt{ \dfrac{(a^2+b^2)(ax_0 + by_0 + c)^2}{(a^2+b^2)^2} } \]

\[ = \sqrt{ \dfrac{(ax_0 + by_0 + c)^2}{a^2+b^2} } \]

\[ = \dfrac{|ax_0 + by_0 + c|}{\sqrt{a^2+b^2}} \]

The absolute value sign is necessary as the distance must be a positive value.

Here, we present a geometric proof.

First, we draw a line parallel to \(L\) that passes through \(P\), which has the equation \(ax+by-(ax_0+by_0)=0\). Then, we construct a right triangle which has height \(d\). Both legs of the right triangle can be obtain by the differences between the interception of \(x\) and \(y\) axis of the two lines. The hypotenuse, by Pythagorean Theorem, is

\[|ax_0+by_0+c|\frac{\sqrt{a^2+b^2}}{ab}\]

Finally, by the area of triangle,

\[\begin{aligned} \frac{1}{2} |ax_0+by_0+c|\frac{\sqrt{a^2+b^2}}{ab}\times d &= \frac{1}{2} |ax_0+by_0+c|^2 \frac{1}{ab} \\ d &= \dfrac{|ax_0 + by_0 + c|}{\sqrt{a^2+b^2}} \end{aligned}\]

## Vectorial Approach

Consider a line given by the points \(\overrightarrow{r} = \overrightarrow{a} + \lambda \overrightarrow{b}\) and the point \(\overrightarrow{x}\). Then, the distance of the line from the point is \[ \left \| {\overrightarrow{x} - (\overrightarrow{a} + \lambda ' \overrightarrow{b})} \right \| \] where \[ \lambda ' = \frac{\vec{x} \cdot \vec{b} - \vec{a} \cdot \vec{b}}{ \left \| \vec{b} \right \| ^2}\]

Consider the foot of the perpendicular on the line from \(\vec{x}\). Let us call this \(\vec{r}\). We want to get the value of \( \left \| \overrightarrow{x} - \overrightarrow{r} \right \| \). By definition, this is the distance from the point to the line.

Since \(\vec{r}\) lies on the line, it satisfies \(\vec{r} = \overrightarrow{a} + \lambda ' \overrightarrow{b} \) for some \(\lambda '\). And since it is perpendicular to the line, we have

\[ (\vec{x} - \vec{r}) \cdot \vec{b} = 0 \\ (\vec{x} - \overrightarrow{a} - \lambda ' \overrightarrow{b} ) \cdot \vec{b} = 0 \\ \vec{x} \cdot \vec{b} - \vec{a} \cdot \vec{b} - \lambda ' \left \| \vec{b} \right \| ^2 = 0 \\ \lambda ' = \frac{\vec{x} \cdot \vec{b} - \vec{a} \cdot \vec{b}}{ \left \| \vec{b} \right \| ^2} \]

The nice thing about this approach is that it is going to work for any number of dimensions.

## Example problems

Find the distance between the point \( (5, 1) \) and the line \( y = 3x + 1 \).

Solution:\[ d = \dfrac{\left| ax_0 + by_0 + c\right| }{\sqrt{a^2 + b^2}} \]

Given \( (x_0, y_0) = (5, 1) \) and \( 0 = 3x - y + 1 \)

\[ d = \dfrac{\left| 3 \cdot 5 - 1 \cdot 1 + 1 \right| }{\sqrt{3^2 + (-1)^2}} \]

\[ d = \boxed{ \dfrac{15}{\sqrt{10}} } \]

Find the distance between the lines \( y = 2x + 5 \) and \( y = 2x + 2016 \).

Solution:Notice that these two lines are parallel (same slope) so we can just choose a point on one of the lines, and then apply the formula.

But wait, wouldn't you get a different result if you try different points? Let's try two different points on the line \( y = 2x + 5 \).

If \( (x_0, y_0) = (1, 7) \) and \( 2x - y + 2016 = 0 \), then applying the formula, we get

\[ d = \dfrac{\left| 2 \cdot 1 - 1 \cdot 7 + 2016 \right| }{\sqrt{2^2 + (-1)^2}}= \boxed{ \dfrac{2011}{\sqrt{5}} } \]

If \( (x_0, y_0) = (2, 9 ) \) and \( 2x - y + 2016 = 0 \), then applying the formula, we get

\[ d = \dfrac{\left| 2 \cdot 2 - 1 \cdot 9 + 2016 \right| }{\sqrt{2^2 + (-1)^2}} = \boxed{ \dfrac{2011}{\sqrt{5}} } \]

For the reader...How do you prove that any point on \( y = 2x + 5 \) can be used in the above formula and still get the same distance between \( y = 2x + 5 \) and \( y = 2x + 2016 \) ? Also, how do you prove that you'll still get the same distance if you use any point on \( y = 2x + 2016 \) and the line \( y = 2x + 5 \)?

Find the distance between the point \( (1,2 , 3 ) \) and the plane \( x+2y-3z = 44 \).

Solution:The formula for this one is an extension of the formula used for finding distance between line and point and is

\[ d = \dfrac{\left| ax_0 + by_0 + cz_0 +d \right| }{\sqrt{a^2 + b^2 + c^2}} \]

Using the information we have,

\[ d= \dfrac{\left| 1 \cdot 1 + 2 \cdot 2 - 3 \cdot 3 + 44 \right| }{1^2 + 2^2 + (-3)^2} = \boxed{\dfrac{40}{\sqrt{14}}} \]

Find the distance between the lines \( \vec{a}(t) = \left \langle 1, 2, 3 \right \rangle + \left \langle 4, 5, 6 \right \rangle t \) and \( \vec{b}(t) = \left \langle 8, 9, 4 \right \rangle - \left \langle -3, -2, 4 \right \rangle t \).

Find the distance between the line \( \vec{a}(t) = \left \langle 0, 0, 6 \right \rangle + \left \langle 1, 2, -2 \right \rangle t \) and the plane \( 2 x + y +2z = 10 \).

## Applications

Find the equation of the angle bisectors between the two distinct lines: \[ a_1x + b_1y + c_1 = 0 \] \[ a_2x + b_2y + c_2 = 0 \]

Notice that there are two angle bisectors between a pair of lines - one bisects the acute angle, and the other bisects the obtuse angle between the lines (if the lines are perpendicular, then there are two right angles formed, anyways).

One of the properties of the angle bisector of two lines, is that every point on it, is equidistant from both lines.

This can be proved by dropping the perpendiculars on the two lines from the point and using congruence of the resulting triangles.If \((x_0, y_0)\) is a point on the angle bisector, we can equate the distances to the lines as: \[ \left|\frac{a_1x_0 + b_1y_0 + c_1}{\sqrt{a_1^2 + b_1^2}}\right| = \left|\frac{a_2x_0 + b_2y_0 + c_2}{\sqrt{a_2^2 + b_2^2}}\right| \]

Removing the absolute value signs, \[ \frac{a_1x_0 + b_1y_0 + c_1}{\sqrt{a_1^2 + b_1^2}} = \pm \frac{a_2x_0 + b_2y_0 + c_2}{\sqrt{a_2^2 + b_2^2}} \]

Now, shift like terms on either side, to make the resulting equation of this form: \[ a_3x_0 + b_3y_0 + c_3 = 0 \]

Here, \[ a_3 = \frac{a_1}{\sqrt{a_1^2 + b_1^2}} \pm \frac{a_2}{\sqrt{a_2^2 + b_2^2}} \] \[ b_3 = \frac{b_1}{\sqrt{a_1^2 + b_1^2}} \pm \frac{b_2}{\sqrt{a_2^2 + b_2^2}} \] \[ c_3 = \frac{c_1}{\sqrt{a_1^2 + b_1^2}} \pm \frac{c_2}{\sqrt{a_2^2 + b_2^2}} \] So, the equation of the angle bisectors will then be: \[ a_3x + b_3y + c_3 = 0 \]

The \( \pm \) tells us that there are two possible values of \(a_3, b_3, c_3 \) - and hence, two angle bisectors, as we discussed above.

**Cite as:**Distance between point and line.

*Brilliant.org*. Retrieved from https://brilliant.org/wiki/distance-between-point-and-line/