BoundingSphere

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

BoundingSphere

Post by Peter Prins »

I noticed some code on the forum where someone made a call to BoundingSphere property. I haven't found such a property in my entities or shapes. Is this a new feature? I'm currently looking for a way to find the tightest possible bounding sphere of my shape centred at its centre of mass. Can I use the BoundingSphere property for that?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BoundingSphere

Post by Norbo »

It's likely that you saw an XNA ModelMesh.BoundingSphere property. There's no such property available on entities or shapes.

However, convex shapes do have a MaximumRadius. This is measured from the center of the shape and is guaranteed to contain the shape. It may, however, be a little looser than it has to be on some shapes. For example, a TransformableShape's MaximumRadius is approximate. However, simpler shapes like the Box, Cylinder, Cone, Sphere and so on have analytically computed MaximumRadius values.
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Re: BoundingSphere

Post by Peter Prins »

Hmmm, I need something that also gives an exact result for things like the CompoundShape. I could probably implement something like MaxDistanceFromPoint myself, for most shapes. However, I could use some help with the MinkowskiSumShape, and I'm not sure if it is even possible for the TransformableShape...
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: BoundingSphere

Post by Norbo »

There's the option of sampling many different directions and keeping the largest radius from the samples. This still isn't exact, but a sufficient number of samples would get you extremely close. If it's an offline process, you could throw a hundred million samples at a shape.

If it has to be done dynamically, this approach is limited. You could probably still get away with many thousands of samples, but that will end up with a little more error. It might only be 0.01 or so, though. Check out the BEPUphysicsDrawer's tessellation of MinkowskiSumShapes and other irregular convexes to see how close (suboptimal!) sampling can get.

This method will work on all convexes. For compounds, you can compute use the radii of constituent shapes combined with the shapes' offsets to find the whole compound's radius.
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Re: BoundingSphere

Post by Peter Prins »

Hmmm.... By using predefined sampling directions I can get an algorithm with a maximum error (as a fraction of the actual maximum distance). That's really all the exactness I need. :)
Post Reply