I'm trying to generate a single bounding sphere for a collection of rigid body shapes. The shapes are limited to sphere, capsule, cylinder, and box. I am currently simplifying the box into a sphere, and the cylinder into a capsule to reduce stress. So as far as what I need to generate a bounding sphere, I can essentially represent each of these shapes with one or two spheres (capsule becomes its two contained spheres).
Currently, I am iterating the spheres, and for each one, combining the result with the new sphere by computing a container sphere of both. The new center is half-way between the extents of both spheres (center = (a.pos + -a.radius + b.pos + b.radius) / 2 ), and the new radius is half of { distance + a.radius + b.radius }.
I've done a little research into how complex it can be to find the spacial center of an arbitrary cluster of points. So I'm wondering if this will work as efficiently (volume space wise) as using one of these functions? If I iterate my spheres and generate the container sphere for each situation, will the end result be efficient as far as only being large enough to encapsulate all of the internal spheres? Or will its center be offset in some weird direction because of the order I iterated them?
My game code is a heavy construction mess at the moment, or I would just test the code under a bunch of situations to see how well it does. If anyone has ever tried this, or can already see that it won't work well, I appreciate the insights.
Thanks!