I want to find the shortest distance between a point $(p,q)$ and the line \[ax + by + c = 0\] (The reason we’re using this equation for a line and not $y=mx+c$ is that the formula happens to come out more neatly this way.) You could imagine yourself standing at the point, with the line as a fence you want to walk to. It doesn’t matter where on the fence you end up, but you want to walk to the closest part. For an extra challenge, try working out a formula for this shortest distance without reading through the following questions.
You will of course walk in a straight line towards the fence, but what straight line would be the shortest? What’s special about this line? Show hint
Now we have to work out how to use all the information we have to write some equations. We could make variables for the coordinates of the closest point on the line. Another good approach would be to shift everything so that $(p,q)$ ends up at the origin, and shift the line by the same amount (it would become $a(x+p) + b(y+q) + c=0$). But what I’ve chosen to do is work in terms of the changes in the coordinates, $\Delta x$ and $\Delta y$, as we move from the point to the line. What does your answer to the last question tell you about $\Delta x$ and $\Delta y$? Show hint
The equation of the line can be rearranged to find the slope: \begin{align*} ax + by + c &= 0\\ by &= -ax -c\\ y &= -\frac{a}{b}x - \frac{c}{b} \end{align*} so its slope is $-a/b$. The slope of the shortest distance from the point to the line must be $b/a$ if they are to be perpendicular. Therefore \[\frac{\Delta y}{\Delta x} = \frac{b}{a}.\]
What does the equation of the line tell us about $\Delta x$ and $\Delta y$? Show hint
The coordinates of the closest point on the line are $(p+\Delta x,q+\Delta y)$. This must satisfy the equation $ax + by + c= 0$, so \[a(p+\Delta x) + b(q+\Delta y) + c = 0.\]
Find $\Delta x$ and $\Delta y$. Show hint
We have two equations: \[ \frac{\Delta y}{\Delta x} = \frac{b}{a}\\ a(p+\Delta x) + b(q+\Delta y) + c = 0 \] Solving the first one for $\Delta y$ gives $\Delta y = b\Delta x /a$ which we can substitute into the second equation: \begin{align*} a(p+\Delta x) + b(q + b\Delta x/a) + c &= 0\\ ap + a\Delta x + bq + b^2\Delta x/a + c &= 0\\ a\Delta x + b^2\Delta x/a &= -ap-bq-c\\ \Delta x \frac{a^2 + b^2}{a} &= -(ap + bq + c)\\ \Delta x &= -\frac{a(ap + bq + c)}{a^2 + b^2}\\ \Delta y &= \frac{b\Delta x}{a}\\ &= -\frac{b(ap + bq + c)}{a^2 + b^2} \end{align*}
Show that \[d = \frac{\abs{ap+bq+c}}{\sqrt{a^2 + b^2}}\] Show answer
\begin{align*} d^2 &= (\Delta x)^2 + (\Delta y)^2\\ &= \frac{a^2(ap + bq + c)^2}{(a^2 + b^2)^2} + \frac{b^2(ap + bq + c)^2}{(a^2 + b^2)^2}\\ &= \frac{(a^2 + b^2)(ap + bq + c)^2}{(a^2 + b^2)^2}\\ &= \frac{(ap + bq + c)^2}{a^2 + b^2}\\ d &= \sqrt{\frac{(ap + bq + c)^2}{a^2 + b^2}}\\ &= \frac{\sqrt{(ap + bq + c)^2}}{\sqrt{a^2 + b^2}}\\ &= \frac{\abs{ap + bq + c}}{\sqrt{a^2 + b^2}} \end{align*}