# 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. – Byte56 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. – Byte56 Nov 16 '13 at 19:13

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