Beispiel #1
0
        /// <summary>Calculates the intersection point between 3 planes</summary>
        /// <param name="inPlane1">The first plane</param>
        /// <param name="inPlane2">The second plane</param>
        /// <param name="inPlane3">The third plane</param>
        /// <returns>The intersection point between the 3 planes.The returned point will consist out NaN values when there is no intersection.</returns>
        static public Vector3 Intersection(CSGPlane inPlane1,
                                           CSGPlane inPlane2,
                                           CSGPlane inPlane3)
        {
            try
            {
                var plane1a = (decimal)inPlane1.a;
                var plane1b = (decimal)inPlane1.b;
                var plane1c = (decimal)inPlane1.c;
                var plane1d = (decimal)inPlane1.d;

                var plane2a = (decimal)inPlane2.a;
                var plane2b = (decimal)inPlane2.b;
                var plane2c = (decimal)inPlane2.c;
                var plane2d = (decimal)inPlane2.d;

                var plane3a = (decimal)inPlane3.a;
                var plane3b = (decimal)inPlane3.b;
                var plane3c = (decimal)inPlane3.c;
                var plane3d = (decimal)inPlane3.d;


                var bc1 = (plane1b * plane3c) - (plane3b * plane1c);
                var bc2 = (plane2b * plane1c) - (plane1b * plane2c);
                var bc3 = (plane3b * plane2c) - (plane2b * plane3c);

                var w = -((plane1a * bc3) + (plane2a * bc1) + (plane3a * bc2));

                var ad1 = (plane1a * plane3d) - (plane3a * plane1d);
                var ad2 = (plane2a * plane1d) - (plane1a * plane2d);
                var ad3 = (plane3a * plane2d) - (plane2a * plane3d);

                var x = -((plane1d * bc3) + (plane2d * bc1) + (plane3d * bc2));
                var y = -((plane1c * ad3) + (plane2c * ad1) + (plane3c * ad2));
                var z = +((plane1b * ad3) + (plane2b * ad1) + (plane3b * ad2));

                x /= w;
                y /= w;
                z /= w;

                var result = new Vector3((float)x, (float)y, (float)z);
                if (float.IsNaN(result.x) || float.IsInfinity(result.x) ||
                    float.IsNaN(result.y) || float.IsInfinity(result.y) ||
                    float.IsNaN(result.z) || float.IsInfinity(result.z))
                {
                    return(MathConstants.NaNVector3);
                }

                return(result);
            }
            catch
            {
                return(MathConstants.NaNVector3);
            }
        }
Beispiel #2
0
 public bool Equals(CSGPlane other)
 {
     if (System.Object.ReferenceEquals(this, other))
     {
         return(true);
     }
     if (System.Object.ReferenceEquals(other, null))
     {
         return(false);
     }
     return(Mathf.Abs(this.Distance(other.pointOnPlane)) <= MathConstants.DistanceEpsilon &&
            Mathf.Abs(other.Distance(this.pointOnPlane)) <= MathConstants.DistanceEpsilon &&
            Mathf.Abs(a - other.a) <= MathConstants.NormalEpsilon &&
            Mathf.Abs(b - other.b) <= MathConstants.NormalEpsilon &&
            Mathf.Abs(c - other.c) <= MathConstants.NormalEpsilon);
 }