Exemple #1
0
RNBoolean R3Contains(const R3Halfspace& halfspace, const R3Triangle& triangle)
{
    // Check whether halfspace contains triangle bounding shape
    if (R3Contains(halfspace, triangle.Box())) return TRUE;

    // Check whether halfspace contains all vertices of triangle
    if (!R3Contains(halfspace, triangle.Vertex(0)->Position())) return FALSE;
    if (!R3Contains(halfspace, triangle.Vertex(1)->Position())) return FALSE;
    if (!R3Contains(halfspace, triangle.Vertex(2)->Position())) return FALSE;

    // Passed all tests
    return TRUE;
}
Exemple #2
0
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;
}