#### Archived

This topic is now archived and is closed to further replies.

# Point->Line-Segment Distance ?

This topic is 5643 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I know how to find the distance of a point to a line but not a line-segment. It could be one of either endpoints or a point in between. Does anyone have the formula ? Thank you.

##### Share on other sites
D=((x1-x2)^2+(y1-y2)^2)^(1/2)

EDIT: Anyway you slice it, you need two points established, unless you're trying to ask something else.

[edited by - nervo on July 2, 2003 12:20:26 PM]

##### Share on other sites
Hi,

Maybe I didn''t explain it correctly.

I want to find the shortest distance between Point C and Line Segment AB (in 2D.)

So Line Segment AB is (Ax,Ay) to Bx,By) and Point C is (Cx,Cy).

Your formula didn''t even take into account the point I''m trying find the distance from.

Thanks.

##### Share on other sites
Find the line perpendicular to the line that passes through the point. Then find the distance from that point to the intersection of the line and the line segment.

How appropriate. You fight like a cow.

##### Share on other sites
quote:
Hi,

Maybe I didn''t explain it correctly.

I want to find the shortest distance between Point C and Line Segment AB (in 2D.)

So Line Segment AB is (Ax,Ay) to Bx,By) and Point C is (Cx,Cy).

Your formula didn''t even take into account the point I''m trying find the distance from.

Thanks.

I wouldn''t say that ''maybe'' you asked incorrectly because this question in no way resembles your original one.

Okay:
Just as Sneftel said you need to find a line that meets perpendicular with the other line segment. Once you understand that concept yields the shortest distance then:

let m = slope of line segment AB

We will call the other line CD with slope m2

Slope of a line that is perpendicular to segment AB is simply the negative inverse of segment AB''s slope. hence

m2 = -(1/m)

Now with the slope determined of segment CD we simply plug that into the equation y = mx + b because now we need to find the constant that gives the needed vertical translation of the line.

Therefore all you would need to do is "plug in" the x and y value of the point that you have into the equation and that will give you the constant if their is one other than zero.

Since you want to find the actual distance now just equate both line forumlas to determine at what point they intersect.
(mx + b) = (m2x + b2)

Finally plug in the two points into the original distance formula that I gave you, and your answer is there after a quick plug and chug.

Got it?

##### Share on other sites
It is really fairly simple to find the shortest distance between a point C and line segment AB. First determine shortest distance between C and the line D that passes through AB. That is, find the intersection E of the line perpendicular to D that contains C. Now test if E is on the line segment AB. If it is, then the shortest distance is the length of CE. If it isn''t, then simply take the shorter of AC and BC.

##### Share on other sites
Heh, this just reminded me of an old calculus problem I had a few years ago. It was exactly this problem. Finding the shortest distance between a point and line segment (not line as some above seem to be doing). It is was in the chapter on the calculus of variations which is suited for this type of minimization problem.

##### Share on other sites
Are you speaking of optimization problems?

Others might not agree with me, but I sorta thought your solution to the above problem was kind of cryptic.

##### Share on other sites
Nervo: OP is trying to find the shortest distance from a point to a line, restricted to a given segment on the line. Mastaba''s solution works.

##### Share on other sites
I see. In that case then the shortest distance would not necessarily be perpendicular to the segment and that would make my solution worthless.

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013597
×