Forked from StagPoint/DoPlanesIntersectAtSinglePoint.cs
Created
February 4, 2023 16:04
-
-
Save victorbstan/4523dafaa53ea01cd89152beb93c8e3d to your computer and use it in GitHub Desktop.
Find intersection point of three planes in C# for Unity
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
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