Shortest Distance between a Point and a Line

There are occasions when we need to know how far we are from a certain object. Point-to-Point and Point-to-Circle are pretty straightforward, but what about the Point-to-Line?

point line perpendicular Shortest Distance between a Point and a LineThe issues with lines is an infinite number of them can be drawn to connect the line and the point, but only one is the shortest: the Perpendicular.

But before we can find which perpendicular passes through the point we need to know this property, the slope of a perpendicular line is the negative reciprocal of the original line:

- 1

Which means the linear equation of the perpendicular line will look like this:

y= – (1 / m) x  + b

So by taking the slope of the original line and the coordinates of the point, we just need to find the y-intercept (b) of the perpendicular line:

b = y + (x / m)

Once we have the linear equation for the perpendicular line we just need to find the intersection point and then calculate the distance between both points. But if we’re dealing with a line segment and not an infinite line, then we also need to check if the intersection point falls within its range before calculating the distance.

However this method is unnecessary for horizontal or vertical lines. Because those are parallel to the axis the process is much more straightforward:

Vertical line:
distance = Lx – Px
Horizontal line:
distance = Ly – Py

You may also like...