Distance between a line and a point

Distance between a line and a point

In many cases, we will need to find the shortest distance between a line a point.

This distance is on the perpendicular of the line. This means that we need to get the intersection point and calculate the distance between the two points.

For instance, if the point is P and the lines intersect at I, we need the distance PI.

Distance between point P(x_0,y_0) and line ax+by+c=0

The point is P(x_0,y_0) is on the line perpendicular to the given line ax+by+c=0

The product of the slopes is m_1m_2=-1

We start by putting ax+by+c=0 in the slope-intercept form

ax+by+c=0
by=-ax-c
y=-\frac{a}{b}x-\frac{c}{b}

That means:
m_1=-\frac{a}{b}

Now we have to find m_2 from m_1:

m_1m_2=-1

-\frac{a}{b}m_2=-1

\frac{a}{b}m_2=1

m_2=\frac{b}{a} after we multiply both sides by \frac{b}{a}

The perpendicular is a line passing through P(x_0,y_0) with a slope of m_2=\frac{b}{a}

We get for the perpendicular:

y-y_0=\frac{b}{a}(x-x_0)

y=\frac{b}{a}x-\frac{b}{a}x_0+y_0

When the two lines meet, they have corresponding coordinates x and y.

We get:

y=-\frac{a}{b}x-\frac{c}{b}

y=\frac{b}{a}x-\frac{b}{a}x_0+y_0

-\frac{a}{b}x-\frac{c}{b}=\frac{b}{a}x-\frac{b}{a}x_0+y_0

x(\frac{b}{a}+\frac{a}{b})=-\frac{c}{b}+\frac{b}{a}x_0-y_0

x(\frac{a^{2}+b^{2}}{ab})=\frac{-ac+b^{2}x_0-aby_0}{ab}

Now we multiply both sides by ab

x(a^{2}+b^{2})=-ac+b^{2}x_0-aby_0

Dividing by a^{2}+b^{2}

\boxed{x=\frac{-ac+b^{2}x_0-aby_0}{a^{2}+b^{2}}}

To find y we use any of the two lines and plug in x expression.

From:

y=-\frac{a}{b}x-\frac{c}{b}

We get

(1)   \begin{equation*}\begin{split}$y&=-\frac{a}{b}(\frac{-ac+b^{2}x_0-aby_0}{a^{2}+b^{2}})-\frac{c}{b}\\& =\frac{a^{2}c-ab^{2}x_0+a^{2}by_0}{b(a^{2}+b^{2})}-\frac{c(a^{2}+b^{2})}{b(a^{2}+b^{2})}\\& =\frac{a^{2}c-a^{2}c-b^{2}c-ab^{2}x_0+a^{2}by_0}{b(a^{2}+b^{2})}\\& =\frac{-b^{2}c-ab^{2}x_0+a^{2}by_0}{b(a^{2}+b^{2})}\\&=\frac{a^{2}y_0-bc-abx_0}{a^{2}+b^{2}}\end{split}\end{equation*}

Finally:

\boxed{y=\frac{a^{2}y_0-bc-abx_0}{a^{2}+b^{2}}}

Now we have the two points, all we need is to calculate the distance:

P=(x_0, y_0)

I=(\frac{ac+b^{2}x_0-aby_0}{a^{2}+b^{2}},\frac{a^{2}y_0-bc-abx_0}{a^{2}+b^{2}})

Distance IP:

(2)   \begin{equation*}\begin{split}d&=\sqrt{(x_0-\frac{-ac+b^{2}x_0-aby_0}{a^{2}+b^{2}})^{2}+ (y_0-\frac{a^{2}y_0-bc-abx_0}{a^{2}+b^{2}})^{2}}\\& =\sqrt{(\frac{a^{2}x_0+ac+b^{2}x_0-b^{2}x_0+aby_0}{a^{2}+b^{2}})^{2}+(\frac{a^{2}y_0-a^{2}y_0+b^{2}y_0+bc+abx_0}{a^{2}+b^{2}})^{2}}\\& =\sqrt{(\frac{a^{2}x_0+ac+aby_0}{a^{2}+b^{2}})^{2}+(\frac{b^{2}y_0+bc+abx_0}{a^{2}+b^{2}})^{2}}\\& =\sqrt{a^{2}(\frac{ax_0+by_0+c}{a^{2}+b^{2}})^{2}+b^{2}(\frac{ax_0+by_0+c}{a^{2}+b^{2}})^{2}}\\& =\sqrt{(a^{2}+b^{2})(\frac{ax_0+by_0+c}{a^{2}+b^{2}})^{2}}\\& =\sqrt{\frac{(ax_0+by_0+c)^{2}}{a^{2}+b^{2}}}\end{split}\end{equation*}

Finally:

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

\textbf{\textcolor{red}{\hl{\huge The end}}}

Print Friendly, PDF & Email

Be the first to comment

Leave a Reply

Your email address will not be published.


*