Page 1 of 1

BoundingSphere

Posted: Sat Feb 16, 2013 11:25 am
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?

Re: BoundingSphere

Posted: Sat Feb 16, 2013 9:04 pm
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.

Re: BoundingSphere

Posted: Fri Mar 01, 2013 8:52 pm
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...

Re: BoundingSphere

Posted: Fri Mar 01, 2013 9:06 pm
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.

Re: BoundingSphere

Posted: Sat Mar 02, 2013 2:03 am
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. :)