void TrianglePlaneRelations(ref Triangle3d triangle, ref Plane3d plane,
                             out Vector3d distance, out Index3i sign, out int positive, out int negative, out int zero)
 {
     // Compute the signed distances of triangle vertices to the plane.  Use
     // an epsilon-thick plane test.
     positive = 0;
     negative = 0;
     zero     = 0;
     distance = Vector3d.Zero;
     sign     = Index3i.Zero;
     for (int i = 0; i < 3; ++i)
     {
         distance[i] = plane.DistanceTo(triangle[i]);
         if (distance[i] > MathUtil.ZeroTolerance)
         {
             sign[i] = 1;
             positive++;
         }
         else if (distance[i] < -MathUtil.ZeroTolerance)
         {
             sign[i] = -1;
             negative++;
         }
         else
         {
             distance[i] = (double)0;
             sign[i]     = 0;
             zero++;
         }
     }
 }
Пример #2
0
        public bool Find()
        {
            if (Result != IntersectionResult.NotComputed)
            {
                return(Result != IntersectionResult.NoIntersection);
            }

            double DdN            = line.Direction.Dot(plane.Normal);
            double signedDistance = plane.DistanceTo(line.Origin);

            if (Math.Abs(DdN) > MathUtil.ZeroTolerance)
            {
                // The line is not parallel to the plane, so they must intersect.
                Quantity      = 1;
                LineParameter = -signedDistance / DdN;
                Point         = Line.PointAt(LineParameter);
                Type          = IntersectionType.Point;
                Result        = IntersectionResult.Intersects;
                return(true);
            }

            // The line and plane are parallel. Determine if they are numerically
            // close enough to be coincident.
            if (Math.Abs(signedDistance) <= MathUtil.ZeroTolerance)
            {
                // The line is coincident with the plane, so choose t = 0 for the
                // parameter.
                Quantity       = 1;
                Point          = Line.PointAt(0);
                CoincidentLine = new Line3d(line.Origin, line.Direction);
                Result         = IntersectionResult.Intersects;
                Type           = IntersectionType.Line;
                return(true);
            }

            Result = IntersectionResult.NoIntersection;
            Type   = IntersectionType.Empty;
            return(false);
        }