Created
December 2, 2011 19:52
-
-
Save slembcke/1424609 to your computer and use it in GitHub Desktop.
Closest Point on Segment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpVect a, b; // segment endpoints | |
cpVect p; // point you are testing | |
cpVect delta = cpvsub(b, a); | |
cpFloat closest_t = cpvdot(delta, cpvsub(p, a))/cpvlengthsq(delta); | |
cpVect closest = cpvlerp(a, b, cpfclamp01(closest_t)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment