Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all points with integer coordinates inside tetrahedron

I am trying to find all the points with integer coordinates that lie inside of a tetrahedron (I want to somehow be able to loop through them). I know the coordinates of the four points (A, B, C, D) that define the tetrahedron.

What I'm currently doing is I find the bounding box of the tetrahedron (minimum and maximum x, y, z coordinates of A, B, C, D) and then do a loop through all of the points inside the bounding box. For every such point, I calculate the barycentric coordinates (using the equations from Wikipedia) and check if the point is inside the tetrahedron (if any of the barycentric coordinates is negative or bigger than 1, the point isn't inside).

Is there a better way to do this? Currently there is around 1/6 chance that the point I am testing (from the bounding box) really lies inside the tetrahedron, so I think I'm doing too many unnecessary computations.

I am working with a list of tetrahedra that I generated by triangulating a bigger volume (I am expanding the volume and want to interpolate the missing values using tetrahedral interpolation). I am not using any external libraries.

like image 306
ppalasek Avatar asked May 15 '12 00:05

ppalasek


People also ask

How do you check if a point is inside a tetrahedron?

If all four distances are positive (or at least nonnegative), then the point lies on the correct side of each plane, and hence is in the tetrahedron. If any distance is strictly negative, the point is not in the tetrahedron.

How many points have integral coordinates in the 1st quadrant lie on the given line?

Total 8 points which lie in the first quadrant.

What are the number of integral points?

So, there are a total 18 integral values.


1 Answers

Another idea for improving:

check if a "rod" parrallel to z-axis (i.e. x=4, y=6) runs through the tetrahedron. If not, no values with (x=4, y=5, z) can be inside.

Else, find where the rod intersects the edge of the tetrahedron (by finding out where the planes that make up the edge of the tetrahedron intersect it).

Say these planes intersect at z=1.3 and z= 10.04. Then you know all points (4,5, 2) to (4,5,10) are inside.

Repeat for all values of x and y.

This should be faster in practice, because it will save you 1 loop.

like image 156
willem Avatar answered Sep 23 '22 16:09

willem