Clipping a convex shape (box) against a plane

kris928
Posts: 9
Joined: Wed Mar 05, 2014 7:22 pm

Clipping a convex shape (box) against a plane

Post by kris928 »

I'd like to clip a convex shape (for now just a box) against a plane. Later I'll probably want to clip it against something more complex, like a tessellated 3d surface.

I was curious if there are already good functions in bullet to do this kind of thing? I found some code to clip a polygon against a plane which I could use, and I also found btPolyhedralContactClipping. It looks like btPolyhedralContactClipping only computes contact points though and does not output the new shape. Is that correct?

I'm doing this to simulate buoyancy and drag in the ocean.

Thanks,
Kris
kris928
Posts: 9
Joined: Wed Mar 05, 2014 7:22 pm

Re: Clipping a convex shape (box) against a plane

Post by kris928 »

I've started implementing this myself for now by clipping each face against the plane.

Next, I'll need to compute the center of mass (centroid) of the clipped mesh. I also know how to do this myself but perhaps bullet can do that park for me?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Clipping a convex shape (box) against a plane

Post by Basroil »

kris928 wrote: Next, I'll need to compute the center of mass (centroid) of the clipped mesh. I also know how to do this myself but perhaps bullet can do that park for me?
If you know the vertices of clipped mesh and it's a convex hull, you can just create a convex hull shape and calculate from there. It's not going to be optimal, but might be good enough?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Clipping a convex shape (box) against a plane

Post by Erwin Coumans »

There are no boolean operations in Bullet indeed. The btPolyhedralContactClipping provides very limited functionality compared to boolean operations: it only approximates the overlap of two convex shapes by a small collection of contact points. You might be able to re-use some of that code for convex versus plane.
kris928
Posts: 9
Joined: Wed Mar 05, 2014 7:22 pm

Re: Clipping a convex shape (box) against a plane

Post by kris928 »

Thanks guys. I've got everything working against a plane for now with custom code. It turns out it's pretty trivial to compute the surface and volume of a polyhedron above and below a plane.