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] > math.MathUtil.ZeroTolerance) { sign[i] = 1; positive++; } else if (distance[i] < -math.MathUtil.ZeroTolerance) { sign[i] = -1; negative++; } else { distance[i] = (double)0; sign[i] = 0; zero++; } } }
// Test-intersection query. public bool Test() { Vector3d P0 = segment.P0; var sdistance0 = plane.DistanceTo(P0); if (Math.Abs(sdistance0) <= MathUtil.ZeroTolerance) { sdistance0 = 0; } var P1 = segment.P1; var sdistance1 = plane.DistanceTo(P1); if (Math.Abs(sdistance1) <= MathUtil.ZeroTolerance) { sdistance1 = 0; } var prod = sdistance0 * sdistance1; if (prod < 0) { // The segment passes through the plane. Type = IntersectionType.Point; return(true); } if (prod > 0) { // The segment is on one side of the plane. Type = IntersectionType.Empty; return(false); } if (sdistance0 != 0 || sdistance1 != 0) { // A segment end point touches the plane. Type = IntersectionType.Point; return(true); } // The segment is coincident with the plane. Type = IntersectionType.Segment; return(true); }
// Test-intersection query. public bool Test() { var DdN = line.Direction.Dot(plane.Normal); if (Math.Abs(DdN) > MathUtil.ZeroTolerance) { // The line is not parallel to the plane, so they must intersect. // The line parameter is *not* set, since this is a test-intersection // query. Type = IntersectionType.Point; return true; } // The line and plane are parallel. Determine if they are numerically // close enough to be coincident. var signedDistance = plane.DistanceTo(line.Origin); if (Math.Abs(signedDistance) <= MathUtil.ZeroTolerance) { Type = IntersectionType.Line; return true; } Type = IntersectionType.Empty; return false; }