RNBoolean R3Contains(const R3Triangle& triangle1, const R3Triangle& triangle2) { // Check whether planes are the same if (!R3Contains(triangle1.Plane(), triangle2.Plane())) return FALSE; // Check whether triangle1's bounding box contains triangle2 if (!R3Contains(triangle1.BBox(), triangle2)) return FALSE; // Check whether points of triangle2 are inside triangle1 for (int i = 0; i < 3; i++) { if (!R3Contains(triangle1, triangle2.Vertex(i)->Position())) return FALSE; } // Passed all tests return TRUE; }
RNBoolean R3Contains(const R3Triangle& triangle, const R3Point& point) { // Check whether triangle bounding shape contains point if (!R3Contains(triangle.Box(), point)) return FALSE; // Check whether triangle plane contains point if (!R3Contains(triangle.Plane(), point)) return FALSE; // Compute whether point is on correct side of each edge const R3Point& p0 = triangle.Vertex(0)->Position(); const R3Point& p1 = triangle.Vertex(1)->Position(); const R3Point& p2 = triangle.Vertex(2)->Position(); R3Plane h01(p1, triangle.Normal(), p1 - p0); if (RNIsNegative(R3SignedDistance(h01, point))) return FALSE; R3Plane plane01(p1, triangle.Normal(), p1 - p0); if (RNIsNegative(R3SignedDistance(plane01, point))) return FALSE; R3Plane plane12(p2, triangle.Normal(), p2 - p1); if (RNIsNegative(R3SignedDistance(plane12, point))) return FALSE; R3Plane plane20(p0, triangle.Normal(), p0 - p2); if (RNIsNegative(R3SignedDistance(plane20, point))) return FALSE; // Triangle contains point return TRUE; }
RNBoolean R3Contains(const R3Plane& plane, const R3Triangle& triangle) { // Return whether plane contains triangle return (R3Contains(plane, triangle.Plane())); }