#### Archived

This topic is now archived and is closed to further replies.

# Bounding Spheres?

This topic is 5828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have implemented a frustum calculation method in my engine and test for sphere. What I need now is an algorithm for creating a bounding sphere from a mesh (I use ms3d meshes with my on renderer). So basically, is there a way to make a bounding sphere (center and radius) from the mesh''s vertices? I have searched google and flipcode, but I didnt get good results.

##### Share on other sites
Actualy there has been COTD on flipcode about generation minimal bouding spheres with some kind recursion algorithem.

You should never let your fears become the boundaries of your dreams.

##### Share on other sites
Creating bounding spheres is quite simple really. You need to first find the center the object, and then test the distance between that and every vertex in the object to get the max. distance. Save that and the radius. To test for collision between two objects, test the sum of their radiuses and against the distance between the two center vertexes. If that distance is greater, the two objects are not colliding.

How do I find the center and the maximum vertex? Well, for the center, you need to create a bounding box and find the midpoint between two diagomally opposite vertexes. But how do you compute the box?! Still easy! You need to find the minimum and maximum x, y, and z values in the entire object. Just iterate through and test each one against the currently stored values.

I don't have much more time, so I can't give you all the algorithms and such. Just search "bounding sphere collision detection" on google.com. You _should_ find something, I've tried it before. At worst you may need to invest in a book. The first of the Gems series explains this very well (that's where I learned it ).

[edited by - aggregate on November 1, 2002 12:39:24 PM]

##### Share on other sites
Some of my code to do a bounding box, I hope this helps:

  //in the headertypedef struct{  float min_x;  float min_y;  float min_z;  float max_x;  float max_y;  float max_z;}box;//whatever function		//clear the bounding box		box.min_x=1200.0f;		box.min_y=1200.0f;		box.min_z=1200.0f;		box.max_x=-1200.0f;		box.max_y=-1200.0f;		box.max_z=-1200.0f;		for(k=0;k<numVertices;k++)			{//get x,y,z, from your mesh				//do the bounding box				if(box.min_x>x)box.min_x=x;				if(box.max_x<x)box.max_x=x;				if(box.min_y>y)box.min_y=y;				if(box.max_y<y)box.max_y=y;				if(box.min_z>z)box.min_z=z;				if(box.max_z<z)box.max_z=z;}

[edited by - Raduprv on November 1, 2002 4:50:05 PM]

##### Share on other sites
Ok thanks for the information!
It helped.

##### Share on other sites
BTW, i think it would be better to addjust your frustrum testing, to use boxes too, not only spheres.

##### Share on other sites
Yes, it supports boxes too.

##### Share on other sites
Then use the boxes, they are better than spheres especially for long/flat/tall objects.

##### Share on other sites
Arent spheres faster?

##### Share on other sites
Use both! First do a quick sphere test then only if sphere is partly inside do bouding box test.

You should never let your fears become the boundaries of your dreams.

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009378
• ### Who's Online (See full list)

There are no registered users currently online

×