Skip to content

Instantly share code, notes, and snippets.

@toxicFork
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toxicFork/ee7949b7febf18378c3d to your computer and use it in GitHub Desktop.
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
//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