Volume of the Intersection Between a Sphere and a Cube?

Please don't post Bullet support questions here, use the above forums instead.
anlumo
Posts: 6
Joined: Thu Nov 29, 2007 3:27 pm

Volume of the Intersection Between a Sphere and a Cube?

Post by anlumo »

Hi,

I've got an unusual problem: I've got a sphere and a cube, both with an arbitrary size and position in space in relation to each other. I want to know the volume of their intersection. The sphere might be completely immersed in the cube, or they might not have any intersection at all.

I thought about treating the box as six planes, and intersecting every plane with the sphere, but then I don't know how to combine these 6 results into a single value (even if I'd find out how to do it, which hasn't happened yet either... that's probably a double integral).

Does anybody have an idea on how to accomplish this feat?

The background here is that I want to voxelize a number of spheres, where each voxelization cell not only stores filled/non-filled, but also how much volume these spheres occupy in every cell.
robagar
Posts: 48
Joined: Fri May 21, 2010 1:49 am

Re: Volume of the Intersection Between a Sphere and a Cube?

Post by robagar »

Doing boolean operations on 3D shapes like that is known as "constructive solid geometry" (see the pic http://en.wikipedia.org/wiki/Constructi ... d_geometry ). I've not used any of them myself, but there are a few CSG libraries aboutyou could look at, like Carve (http://carve-csg.com/)

hth
Rob
anlumo
Posts: 6
Joined: Thu Nov 29, 2007 3:27 pm

Re: Volume of the Intersection Between a Sphere and a Cube?

Post by anlumo »

Thank you for the reply.

Unfortunately, CSG doesn't help me here, as I'm not interested in the shape of the resulting object as a polygonal soup (which this library seems to provide), but in the volume this intersection occupies.
Johan Gidlund
Posts: 26
Joined: Mon Jun 01, 2009 2:21 pm
Location: Sweden

Re: Volume of the Intersection Between a Sphere and a Cube?

Post by Johan Gidlund »

Of the top of my head... please correct any errors I made if they exist :)

Take an arbitrary axis parallell to one of the sides of the cube.
Take the plane with this normal at an arbitrary point inside the cube on the normal.
Get the equation of the intersection of this plane with the sphere which is a circle, a point or nothing.
Find the equation for the intersection of this circle and the square defined by the cube at that point.
Integrate over the extents of the cube.