Detecting if a point is inside a body

User avatar
fractile
Posts: 7
Joined: Fri May 10, 2013 8:13 am

Detecting if a point is inside a body

Post by fractile »

How can I easily detect if a point is located inside a body (triangle mesh)? I'm doing some ray casting and I need to know if the start point is already inside the body.

I searched the forum and found some topics on using ghost objects, but if I understood correctly those don't detect completely enclosed bodies and they seem a bit overkill in case of simple static point-inside-shape test.
Ateocinico
Posts: 12
Joined: Sat Jun 29, 2013 5:55 pm

Re: Detecting if a point is inside a body

Post by Ateocinico »

If you are using rigid bodies, you can get their collision shape with the procedure "getCollisionShape". Collision shapes have an overloaded procedure named "isInside" defined as:
virtual bool isInside(const btVector3& pt,btScalar tolerance) const
User avatar
fractile
Posts: 7
Joined: Fri May 10, 2013 8:13 am

Re: Detecting if a point is inside a body

Post by fractile »

Unfortunately many of the collision shapes that I use are concave triangle meshes and the isInside() is only available for some of simple the convex shapes.

Now that I though about it more I found an easier way to solve my problem. Since the collision shapes are essentially laid out on a 2D plane I can simply cast a ray from "above the plane" to the tested point and see if the ray hits the mesh before the point. This is not perfect, but should be sufficient for my needs.
mything
Posts: 1
Joined: Sun Nov 03, 2013 4:03 pm

Re: Detecting if a point is inside a body

Post by mything »

That is easy.
detecting collistion point on the surface relate to poligon points order.
so you may prepare two poligon model.

but you can use this way.
ray(from, to) // check outside to inside.
ray(to, from) // check inside to outside - (inside to outside check in one mesh.)