• Forum
  • Lounge
  • Understanding point-segment distance for

 
Understanding point-segment distance formula

I've been trying to figure this out for two days. I'd like to ask a professor or something but I have no idea where to find one, so...

This is the best (read: easiest to understand) solution I could find. http://forums.codeguru.com/showthread.php?194400-Distance-between-point-and-line-segment&p=538288#post538288


Let the point be C (Cx,Cy) and the line be AB (Ax,Ay) to (Bx,By).
Let P be the point of perpendicular projection of C on AB. The parameter
r, which indicates P's position along AB, is computed by the dot product
of AC and AB divided by the square of the length of AB:

(1)
AC dot AB
r = ---------
||AB||^2


I think 'r' is "how much of AB" we need to move, from A along the line passing through A and B, to find the point of projection of C on AB. But where does this formula come from? Why AC and AB and why do I need their dot product?
Last edited on
http://upload.wikimedia.org/wikipedia/commons/9/98/Projection_and_rejection.png
as you can see a = a_1+a_2
the distance that you want to compute is a_2 = a - a_1,
(in your example AC is a, AP is a_1)

Now from trigonometry
\cos \theta = \frac{ adjacent }{ hypotenuse } = \frac{ |a_1| }{ |a| }
And from definition
dot(u,v) = |u| |v| \cos \theta

So dot(a,b) = |a| |b| \frac{ |a_1| }{ |a| }
And finally |a_1| = |AP| = r = \frac{ dot(a,b) |a| }{ |a| |b| } = \frac{ dot(a,b) }{ |b| }
I think 'r' is "how much of AB" we need to move, from A along the line passing through A and B, to find the point of projection of C on AB.
It looks like vector projection, where r is the vector AP from the projection of AC on AB (if I read it right).

But where does this formula come from?
It's vector calculus.
See this, it may help http://www.math.oregonstate.edu/home/programs/undergrad/CalculusQuestStudyGuides/vcalc/dotprod/dotprod.html
Thank you very very much. Using your formula and resource I was able to figure out the logic behind the calculations.
Thanks to both of you.
Topic archived. No new replies allowed.