Created
September 25, 2018 17:57
-
-
Save StagPoint/2eaa878f151555f9f96ae7190f80352e 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
In my project, it works very well if I use
Mathf.Abs(det)
. I haven't figured out theintersectionPoint
formula, but it seems to be applicable to all situations.