Another method for checking if a tetrahedron (with vertices A, B, C, D) contains a point (P, here P = 0) is checking if there exists a convex combination of the vertices yielding the points:
| Ax + By + Cz + Du = P where x + y + z + u = 1 and x,y,z,u >= 0
|
(A,B,C,D are 3d vectors, x,y,z,u are scalar variables).
As you can see, a convex combination is a linear combination with two additional properties. Ax + By + Cz + Du = P and x + y + z + u = 1 together give you a 4x4 linear equation system which you would need to solve. It should have a unique solution (if A, B, C, D span an actual tetrahedron and do not lie all on the same plane), then you can check if x,y,z,u >= 0.
This is probably something you would not want to do in an efficient implementation. But it gives theoretical insight on the number of if-statements you could need.
If you think further about this, you can solve the entire problem of deciding which part of the tetrahedron to choose from the solution of this equation system, more explicitly from the signs of x,y,z,u. We already saw one case: if x,y,z,u >= 0, then take the whole tetrahedron (ABCD). If only three have sign >= 0 (say x, z, u), then take the side consisting of these 3 vertices (ACD). If only two have sign >= 0 (say x, u), then take the corresponding edge (AD). If only one has positive (or non-negative) sign, say x, then the corresponding vertex is the right one (A). The case that all of them are negative or zero is not posible, since x + y + z + u = 1. Also we can apply the trick used by Casey in the video to further cut down the number of cases: Each of the simplices returned contains the vertex A, since from the previous step of the algorithm we can already deduce that x can not be negative or zero.
This cuts the number of if statements needed from 6, not to 5, not to 4, but to 3 if statements (if y >= 0, if z >= 0, if u >= 0, each yielding a different case).
But you can immediately see that I cheated. While tests for y,z,u >= 0 are very cheap the computation of y,z,u are not. They can be computed explicitly using the Cramer rule (which I think is what the papers mentioned in the video have done) or using Gauss elimination, even without doing a division. The Cramer rule is very computation intensive (at least for 4x4) and Gauss elimination without division could cost you precision of the result, as far as I see it (I am no numerical expert). The number of additions / multiplications you need for Gauss should be not too big (I estimate ~60 multiplications for the calculation of the signs of y,z,u), this should not be to bad compared to the calculations used for the plane equations.
With this one could also try to reduce the number of if statements in the triangular case. Casey lists 5 different results of the function, but two of them seem very similar (the cases "origin is above the triangle" and "origin is below the triangle"). Maybe we only need one of them ("origin is above or below the triangle"), so this reduces the number of cases to 4 and two if statements could theoretically suffice.