<p>There are many ways, but the fastest I think is to create an octtree for your cube and choose a small subdivision level. Then do simple collision detection of the cube to the sphere. If the sphere collides with the cube, subdivide it into 8 smaller cubes. Test each of those cubes and repeat. When you are finished, you will know how many cubes have intersected the sphere, just multiply their dimensions by the number of intersections and you have a close approximation of total volume.</p>

<p>You may want to say that a cube collides with a sphere if its center lies within one radius of the spheres center.</p>

<p>I recently did something similar for a CNC simulator I wrote.</p>

<p>Good luck!</p>

<p>As far as the second part of your question, there would have to be constraints. If the cube is substantially smaller than the sphere, it may not be possible to satisfy your volume requirements. Given that constraints are in place, this method is fast enough that you could just drive your sphere into the cube until your required volume is met.</p>

CC BY-SA 4.0
2019-09-06T06:24:41.467Z
2019-09-06T06:30:13.217Z
2019-09-06T06:30:13.217Z
Gabriel Rohweder
<p>Is there any way to compute the volume when a sphere intersects a AABB(cube), with different centers. Also i want to be able given a percentage of sphere's volume to  to place the sphere's center in a point in 3D space where it intersects the AABB and satisfies that intersected volume. </p>

<computational-geometry>
Volume of Intersection of Cube and Sphere
Code Master
# Volume of Intersection of Cube and Sphere

(Asked by: username_0 on 2019-08-07)

Is there any way to compute the volume when a sphere intersects a AABB(cube), with different centers. Also i want to be able given a percentage of sphere's volume to to place the sphere's center in a point in 3D space where it intersects the AABB and satisfies that intersected volume.

**Tags:** computational-geometry


---

## 1 answers

### Answer by username_1 on 2019-09-06. Score: 0 | Accepted answer

There are many ways, but the fastest I think is to create an octtree for your cube and choose a small subdivision level. Then do simple collision detection of the cube to the sphere. If the sphere collides with the cube, subdivide it into 8 smaller cubes. Test each of those cubes and repeat. When you are finished, you will know how many cubes have intersected the sphere, just multiply their dimensions by the number of intersections and you have a close approximation of total volume.

You may want to say that a cube collides with a sphere if its center lies within one radius of the spheres center.

I recently did something similar for a CNC simulator I wrote.

Good luck!

As far as the second part of your question, there would have to be constraints. If the cube is substantially smaller than the sphere, it may not be possible to satisfy your volume requirements. Given that constraints are in place, this method is fast enough that you could just drive your sphere into the cube until your required volume is met.


---

