Last active
August 29, 2015 14:17
-
-
Save toxicFork/ee7949b7febf18378c3d to your computer and use it in GitHub Desktop.
Algorithm to get the distance of a point in the world to a plane in the world. Gist created for http://wp.me/p1tYzm-38
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
//http://mathworld.wolfram.com/Point-PlaneDistance.html | |
float distanceToPlane(float3 planePosition, float3 planeNormal, float3 pointInWorld) | |
{ | |
//w = vector from plane to point | |
float3 w = - ( planePosition - pointInWorld ); | |
return ( | |
planeNormal.x * w.x + | |
planeNormal.y * w.y + | |
planeNormal.z * w.z | |
) / sqrt ( | |
planeNormal.x * planeNormal.x + | |
planeNormal.y * planeNormal.y + | |
planeNormal.z * planeNormal.z | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment