# Thread: Finding the point on a line closest to another point

1. ## Finding the point on a line closest to another point

I'm sure we've all heard the classic vector algebra problem: "Find the shortest distance from the line y=mx+b to the point (x0, y0)". I'm interested in a variation on this problem that I've been bashing my head against for a couple days now.

I'm not concerned with the shortest distance, but the point on the line where that shortest distance occurs. To make the problem worse, I'm dealing with three dimensions.

For example, I have a line defined by two points, let's say (0,1,2) and (6,2,7). I want to find the point on this line closest to the point (3,-7,-4).

I'm comfortable with vector math, including dot and cross products, normalizing, addition, all that. I'm just not sure what combination of operations will get me the point I'm looking for.

2. ## Re: Finding the point on a line closest to another point

Hey MofoMan2000.

Try deriving a norm expression that gets the distance from a fixed point, to a position on the line. If you have a parameterized x(t), y(t), z(t), then the norm will simply be ||.||^2 = (x(t) - x0)^2 + (y(t) - y0)^2 + (z(t) - z0)^2 where (x(t),y(t),z(t)) is the position of the line at parameter t, and (x0,y0,z0) is the fixed point.

By minimizing ||.||^2 (which is easier than minimizing the non-square version since you have square roots) you can find the closest point that way.

3. ## Re: Finding the point on a line closest to another point

True, I could minimize the distance function, it's a good method. But it isn't very efficient from a programmatic point of view. I was thinking more of using a vector-based approach, since the vector from the line to the point would, of course, be orthogonal to the line. If I can find that vector, I can find the point on the line, or vice versa.

4. ## Re: Finding the point on a line closest to another point

Originally Posted by MofoMan2000
I'm not concerned with the shortest distance, but the point on the line where that shortest distance occurs. To make the problem worse, I'm dealing with three dimensions.

For example, I have a line defined by two points, let's say (0,1,2) and (6,2,7). I want to find the point on this line closest to the point (3,-7,-4).
Name the points: $A: (0,1,2),~B: (6,2, 7),~\&~M: (3,-7,-4)$.

Write the equation of the plane, $\Pi$ , through $M$ with normal $\overrightarrow {AB}$.

The point you want is $\overleftrightarrow {AB} \cap \Pi$.

5. ## Re: Finding the point on a line closest to another point

Originally Posted by Plato
Name the points: $A: (0,1,2),~B: (6,2, 7),~\&~M: (3,-7,-4)$.

Write the equation of the plane, $\Pi$ , through $M$ with normal $\overrightarrow {AB}$.

The point you want is $\overleftrightarrow {AB} \cap \Pi$.
Thanks, that got me exactly what I needed.

First, I define vector $\overrightarrow {Q}$ as $\overrightarrow {AB}$ normalized.
I then define my line by three parametric equations using the normal as coefficients for a parameter t, and add point $A$.
Then I construct the equation for a plane using normal $\overrightarrow {Q}$ and point $M$.
I substitute my parametric equations for x y and z into the plane equation and solve for t.
When I plug that t back into the parametric equations for x y and z y I have my point.

Thanks again!

6. ## Re: Finding the point on a line closest to another point

Hi,
I've attached a general formula for the point you seek. The formula is probably not worth remembering, but the technique used to derive the formula is worthwhile, I think. The formula is useful in a programming environment.