AABB to sphere

Started by
2 comments, last by Amadeus 15 years, 10 months ago
It is very easy to compute the bounding sphere to an AABB: - use center of box as sphere origin - use distance between center and a corner as sphere radius. Now my question is simply: is there a way to compute this same sphere, but without using a square root (distance calculation) ? Intuitively, I would say probably not, but I would like to be sure I'm not missing a trick or something... Y.
Advertisement
nope. No way around it, I believe.

Everything is better with Metal.

The only thing I can think of is to represent a sphere in terms of the radius2, if you're using such a sphere for collision detection alone then that may well be suitable.
If you assume the aabb is actually enclosed by a cube the size of your largest half axis, you should be able to multiply the largest half axis by the square-root of 3 and get a sphere radius that will enclose the cube. This may not be accurate enough for you if your aabb are far from being ideal cubes, but the sphere will surround the aabb.

If you have a unit sphere centered at the origin, an aabb that encompasses it will have a corner at (1,1,1), whose distance from the origin is sqrt(1*1 + 1*1 + 1*1) = sqrt(3), which since the half axii are 1, mean that a sphere bounding the cube equals the sqrt(3) times any of the half axii.

For non-cube aabb, taking a suggestion from a collision detection article a while back, whereby you divided the interacting variables by the half-axii to convert things from ellipsoid into unit-sphere space, multiplying your half-axii by the sqrt(3) will get you the relevant bounding ellipse instead. Dividing by the sqrt(3) will get you the enclosed sphere/cube or ellipse/aabb.

In 2d this would be the sqrt(2) instead.

I hope that makes sense.

- revel8n

[Edited by - Amadeus on June 16, 2008 1:35:20 PM]
----------------------------"Whatever happens, happens..." - Spike"Only the strong survive, if they choose to leave those weaker than themselves behind." - Myself

This topic is closed to new replies.

Advertisement