Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the point is in the tetrahedron or not?

I know all coordinates of tetrahedron and the point I would like to determine. So does anyone know how to do it? I've tried to determine the point's belonging to each triangle of tetrahedron, and if it's true to all triangles then the point is in the tetrahedron. But it's absolutely wrong.

like image 797
Denis Lolik Avatar asked Aug 07 '14 10:08

Denis Lolik


1 Answers

For each plane of the tetrahedron, check if the point is on the same side as the remaining vertex:

bool SameSide(v1, v2, v3, v4, p)
{
    normal := cross(v2 - v1, v3 - v1)
    dotV4 := dot(normal, v4 - v1)
    dotP := dot(normal, p - v1)
    return Math.Sign(dotV4) == Math.Sign(dotP);
}

And you need to check this for each plane:

bool PointInTetrahedron(v1, v2, v3, v4, p)
{
    return SameSide(v1, v2, v3, v4, p) &&
           SameSide(v2, v3, v4, v1, p) &&
           SameSide(v3, v4, v1, v2, p) &&
           SameSide(v4, v1, v2, v3, p);               
}
like image 199
Nico Schertler Avatar answered Sep 21 '22 13:09

Nico Schertler