lcpp-org / RustBCA

A free, open-source Binary Collision Approximation (BCA) code for ion-material interactions including sputtering, implantation, and reflection
https://github.com/lcpp-org/RustBCA/wiki
GNU General Public License v3.0
42 stars 15 forks source link

[question] What happens if running a trimesh object that is not watertight? #238

Closed Sir-Goshawk closed 9 months ago

Sir-Goshawk commented 9 months ago

Does it affect the inside_trimesh function or other logical as well?

drobnyjt commented 9 months ago

RustBCA determines if a point is inside a trimesh in a similar way to the ray casting solution to the point-in-polygon problem.

First, it checks if the point is inside the bounding box volume of the mesh. If so, it then raycasts in an arbitrary direction, in this case (1.0, 0.0, 0.0). If there are no intersections with the mesh, it is outside the mesh. If there are, it then determines if the first face intersected by that ray is an inside face or an outside face by comparing the direction of the normal to the direction of the ray. This is where the code will break when normals are not all outward-facing.

If the mesh is not watertight, there may be regions of the interior where this ray fails to intersect with the trimesh even for points inside the mesh, resulting in erroneous "not inside" determinations. Hope this helps!

Sir-Goshawk commented 9 months ago

I see, thank you.