Skip to content

Instantly share code, notes, and snippets.

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 victorbstan/4523dafaa53ea01cd89152beb93c8e3d to your computer and use it in GitHub Desktop.
Save victorbstan/4523dafaa53ea01cd89152beb93c8e3d to your computer and use it in GitHub Desktop.
Find intersection point of three planes in C# for Unity
private bool planesIntersectAtSinglePoint( Plane p0, Plane p1, Plane p2, out Vector3 intersectionPoint )
{
const float EPSILON = 1e-4f;
var det = Vector3.Dot( Vector3.Cross( p0.normal, p1.normal ), p2.normal );
if( det < EPSILON )
{
intersectionPoint = Vector3.zero;
return false;
}
intersectionPoint =
( -( p0.distance * Vector3.Cross( p1.normal, p2.normal ) ) -
( p1.distance * Vector3.Cross( p2.normal, p0.normal ) ) -
( p2.distance * Vector3.Cross( p0.normal, p1.normal ) ) ) / det;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment