[Math] How to find if a 3d point is in/on/outside of tetrahedron

3dgeometrytriangles

How can I find if a 3d point is in/on/outside of tetrahedron defined by 3d coordinates (the point and the tetrahedron)?
This is what I found on ethernet:

You now just check if a point $P$ is on the other side of the plane. The normal of each plane is pointing away from the center of the tetrahedron. So you just have to test against $4$ planes. Your plane equation looks like this: $ax+by+cz+d=0$ Just fill in the point values $(x,y,z)$. If the sign of the result is $>0$ the point is of the same side as the normal, result $== 0$, point lies in the plane, and in your case you want the third option: $<0$ means it is on the backside of the plane. If this is fulfilled for all $4$ planes, your point lies inside the tetrahedron.

So if this is correct, I'm struggling to understand the equation $ax+by+cz+d=0$. If I'm correct the $x,y,z$ stand for the point coordinates, what do $a,b,c,d$ stand for ?

Best Answer

One simple approach arises from the fact that a tetrahedron is a 3-simplex. This is a 3d analogue of a common technique used to check if a point is inside a triangle, widely used in computer graphics.

Given a non-degenerated tetrahedron whose four vertices are non-coplanar points $P_0,P_1,P_2,P_3\in\mathbb{R}^3$ and a point $P\in\mathbb{R}^3$, there is a unique way to represent $P$ using barycentric coordinates: $$ P = u_0 P_0 + u_1 P_1 + u_2 P_2 + u_3 P_3 \text{,} $$ where $u_0,u_1,u_2,u_3\in\mathbb{R}$ and $u_0+u_1+u_2+u_3=1$. Knowing that all these coefficients sum up to $1$ we can replace $u_0$ by $1-u_1-u_2-u_3$ and transform the above equation to the following form: $$ u_1 (P_1-P_0) + u_2 (P_2-P_0) + u_3 (P_3-P_0) = (P-P_0) \text{.} $$ This linear equation is pretty straightforward to solve. Having all the coefficients computed, we may perform the test:

  • $P$ is inside the tetrahedron $\iff$ all of $u_0,u_1,u_2,u_3$ are positive;
  • $P$ is in outside of the tetrahedron $\iff$ any of $u_0,u_1,u_2,u_3$ is negative;
  • $P$ is on a face of the tetrahedron $\iff$ one of $u_0,u_1,u_2,u_3$ is $0$ and all the other are positive;
  • $P$ is on an edge of the tetrahedron $\iff$ two of $u_0,u_1,u_2,u_3$ are $0$ and all the other are positive;
  • $P$ is a vertex of the tetrahedron $\iff$ three of $u_0,u_1,u_2,u_3$ are $0$ and the other one is positive ($=1$).
Related Question