Original Post
Hi!
I have one point and one line.
How do I compute the nearest point on the line? I have the normal for the line.
line 1 is:
r = P1 + sV1
where P1 is a point on your original line, s is a scalar and V1 is your direction vector for that line.
line 2 is:
r = P2 + tV2
where P2 is the point you are testing, V2 is the normal to your original line, and t is a scalar
Now all you do is equate the two:
P1 + sV1 = P2 + tV2
solve for either s or t,
put s of t back into your equation and you have your point!
(PS this can only be guaranteed in 2D space, as in 3D space, your normal to the line might not lie on the same plane as the point you are testing)
-------
t = (linedirection . (point - lineorigin)) / (linedirection . linedirection)
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more