bepuphysics2 icon indicating copy to clipboard operation
bepuphysics2 copied to clipboard

API for checking if a point is inside of a convex shape or not

Open Frooxius opened this issue 7 months ago • 1 comments

Hello again!

I've got another thing (this time not a bug x3) - we use BepuV2 quite a lot of a lot of spatial queries, even outside of physics, because it has a lot of good building blocks for those. One of the things that'd be useful is ability to determine if points are inside shapes or not - e.g. to implement stuff like convex hull selection or a boolean sampling system to determine if particular point is inside volume or not (I'm adding a system to our project called spatial variables).

Is there an API/way to determine if a single point is inside of a convex shape or not? I'm particularly interested in ConvexHull, but any convex shape would be useful.

I noticed the IConvexShape implements the RayTest method, so they all support ray testing, but what if my check is just a single point, rather than a ray?

Could RayTest be used for this potentially with zero travel distance (or maybe just a miniscule one, but that feels "wrong")? Or would this need to be a separate API?

Frooxius avatar Apr 29 '25 17:04 Frooxius

quickanswer: yup, zero length rays should work (or just any length ray and check for having a T value of 0). If performance is critical, point containment tests can be faster than ray tests in principle, and the convex hull point containment test would be pretty easy to write given that it has AoSoA bounding planes.

(In an ideal world, there would be point containment tests as a standard part of the API just to take advantage of those specialization opportunities. Probably should just do that at some point.)

RossNordby avatar May 02 '25 02:05 RossNordby