Shortest distance between a point and a line segment

Posted by Eli Courtwright on Stack Overflow See other posts from Stack Overflow or by Eli Courtwright
Published on 2009-05-11T17:47:52Z Indexed on 2012/09/06 3:38 UTC
Read the original article Hit count: 245

Filed under:
|

I need a basic function to find the shortest distance between a point and a line segment. Feel free to write the solution in any language you want; I can translate it into what I'm using (Javascript).

EDIT: My line segment is defined by two endpoints. So my line segment AB is defined by the two points A (x1,y1) and B (x2,y2). I'm trying to find the distance between this line segment and a point C (x3,y3). My geometry skills are rusty, so the examples I've seen are confusing, I'm sorry to admit.

© Stack Overflow or respective owner

Related posts about language-agnostic

Related posts about geometry