# How to generate AABB, OBB & Sphere from polygon soup

How can I generate AABB, OOBB and Sphere from a polygon soup, where the bounding volumes are defined as follows:

• AABB should be specified by min(x,y,z) max(x,y,z)
• OOBB should be specified by min(x,y,z) max(x,y,z) and a quaternion for rotation
• Sphere is specified as position(x,y,z) and radius
• OBB cannot be specified by min and max. – concept3d Nov 16 '13 at 13:40
• @concept3d How can they be specified then? – Soapy Nov 16 '13 at 14:00
• OBB are bounding boxes that are oriented with the object. That means you'll need to define an orientation for your soup. It could be the same as the AABB to start with. Or it could be defined by some other rules, like the direction from the average center to the vertex density center. Totally up to you. – MichaelHouse Nov 16 '13 at 18:22
• @Byte56 So the orientation could be represented by a quaternion? – Soapy Nov 16 '13 at 19:06
• Yes. OOBB is similar to a AABB except it rotates with the object. So when the object is at the "default" position, or its local axis is aligned to that of the global axis, the OOBB and AABB are the same bounds. You need to have the rotation defined if you want to get the OOBB. You can do that with a quaternion. – MichaelHouse Nov 16 '13 at 19:13

## 1 Answer

Iterate through your soup and collect the following information:

• Per vertex:
• Maximum and Minimum x, y and z values

Something like:

for each polygon in soup
for each vertex in polygon
if vertex.x > maxX
maxX = vertex.x
if vertex.x < minX
minX = vertex.x

// and so on for y and z

sphereCenter = minX + (maxX-minX)/2, minY + (maxY-minY)/2, minZ + (maxZ-minZ)/2
sphereRadius = max((maxX-minX)/2,(maxY-minY)/2,(maxZ-minZ)/2)
boundMin = minX, minY, minZ
boundMax = maxX, maxY, maxZ


That gives you both the bounding sphere and the AABB bounding box.

In order to get an OOBB you'll need some kind of orientation information for the soup. Then you'll have to find the center of the soup, negate the orientation information by rotating all the vertices in the soup around the common center. Now you have an axis aligned soup. You can perform the same steps as above, then rotate everything (including the eight corners of the axis aligned bounding box) back around the common center.

• That will definitely get you a bounding sphere, though not necessarily the smallest one. If you want to get fancy, have a look at en.wikipedia.org/wiki/Smallest-circle_problem – Incredulous Monk Nov 20 '13 at 23:30
• That's true. It'll probably get close enough for this problem, but thanks for the link that's an interesting topic. – MichaelHouse Nov 20 '13 at 23:37