Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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