Created
September 19, 2015 18:51
-
-
Save v3c70r/c389168cef4382e6a036 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @brief Get distance from a point to line | |
* | |
* @param p0 The point | |
* @param p1 Starting point of line | |
* @param p2 End point of line | |
* | |
* @return distance*distance | |
*/ | |
float pointLineDistance(const glm::vec2 &p0, const glm::vec2 &p1, const glm::vec2 &p2) | |
{ | |
return | |
( (p2.y - p1.y) * p0.x - (p2.x-p1.x)*p0.y + p2.x*p1.y - p2.y*p1.x) * | |
( (p2.y - p1.y) * p0.x - (p2.x-p1.x)*p0.y + p2.x*p1.y - p2.y*p1.x) / | |
((p2.y - p1.y) * (p2.y - p1.y) + (p2.x-p1.x)*(p2.x-p1.x)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment