Re:Coding Horror: Should Competent Programmers be "Mathemati...
by ori_b on Wednesday April 01, 2009 @02:18PM
(#542209)
Draw a triangle; Do the trig.
Between any arbitrary point on a line segment, the point on the line segment that contains the shortest point, and the point in question, you have a triangle.
You can take the length between any point on the line segment and the point in space, find it's magnitude squared, and subtract the magnitude squared of it's projection along the line segment. This gives you the distance of between the point and line segment squared by pythagoras' theorem.
x
/|
/ |
/ |
-a****-----
a is the arbitrary point on the line, the *s are the projected segment, and x is the point you want to find the distance from.
Does anyone have an elegant solution?