Bounding box calculation for a sphere

chessweb
Posts: 1
Joined: Mon Apr 04, 2011 2:21 pm

Bounding box calculation for a sphere

Post by chessweb »

Hi,

I generated a btCollisionShape object via

Code: Select all

btCollisionShape * collShape = new btSphereShape(1.0f);
Now,

Code: Select all

collShape->getBoundingSphere(center, radius)
gives a radius of 1.732 which is due to the fact that the getBoundingSphere method always perfoms a bounding box calculation before it assigns a value to the radius of the bounding sphere. Naturally, the radius of the bounding sphere results in sqrt(3) when the original sphere has radius one.

I don't see how this makes sense for a collision shape that results from a perfect sphere. Is there a reason for the bounding box calculation, even though the body in question is a sphere?
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Bounding box calculation for a sphere

Post by dphil »

My guess is just that it is a generic bounding volume to cover a variety of shapes. Obviously it's not as tight a sphere as it could be for an actual btSphereShape, but there are other shapes (with the same bounding box) where such a tight sphere would be too small. A bounding sphere around the bounding box is the minimum guaranteed bounding sphere for any shape, so it's a good generic approach. Granted, I suppose for some shapes, specialized versions of getBoundingSphere could be written for better accuracy; perhaps they just wanted the bounding sphere to follow consistent logic between shapes (or, if you know you have a btSphere in the first place, might as well just retrieve the origin/radius manually).