I wrote a script to detect if a point is inside a closed mesh. To do this, I fire 6 raycasts (+X, -X, +Y, -Y, +Z, -Z). If all of them hit properly, I assume the point is inside.
The issue: sometimes, even though the point is clearly inside the object (see image below), some of the raycasts fail and return no hit
After testing a bit, I realized that the bigger the query distance, the more likely I am to get false negatives. It’s like large queries break the detection somehow. And honestly, I’d rather not manually tweak the ray length for every mesh I test.
So my questions are:
Why does a larger query make it unreliable?
Is there a solid method to make the detection work regardless of ray size?
Is the raycast long enough to detect a collision, but doesn’t because the length is too long? Or is the raycast too short to actually hit the walls of the organ? What numbers are you using? I can’t really tell from the screenshot.
The raycast length I’m using is 1000.0, but my mesh is relatively small — for reference, the point radius I’m working with is 0.001. The most accurate raycast I can currently achieve is with a length of 10. However, I would like to be able to use any raycast length I want, so it can adapt to different mesh sizes.