Question

I am given a right rectangular prism (i.e. a box) and an arbitrary convex solid within it, such that the box matches the AABB (axis-aligned bounding box) of the aforementioned solid.

I would like to "carve out" the solid from the box and, in doing so, split the box into several convex segments around the solid's faces (hopefully, if the solid has n faces, then n segments). Basically, make a solid-shaped hole in the box. Here's a picture of what I mean:

enter image description here

However, this would also have to work for shapes like this:

enter image description here

The problem is, I think, much easier with axially symmetric shapes like right prisms and pyramids than with centrally symmetric shapes like spheres (as you can see, the spheres aren't proper spheres; they have a finite number of flat sides). I'm looking for a general algorithm that would work with any solid, no matter how complex or rotated or tilted it may be.

No correct solution

OTHER TIPS

As edited there is a solution to your question if the enclosed shape is restricted to having flat faces. In particular, project lines from the centroid of the enclosed shape outward through each of the vertices of the enclosed shape, out to the enclosing bounding box. Now cut the enclosing material along each face between two of these lines - that is, along the outward projection of each edge of the enclosed shape. Each of these cuts is flat since it is part of a plane defined by the centroid and two vertices. Each of the resultant pieces into which the surrounding material is cut will be convex.

In the original wording of the question with arbitrary internal shapes, if you want the number of segments to be finite, you are out of luck in the general case. In particular, if the enclosed shape is a sphere, any finite portion of the sphere's surface, while convex in relation to the sphere, is necessarily concave in relation to whatever other segment, outside of the sphere, that it is a part of; such an outside segment will thus not be convex, and will not meet your requirement.

Build a list of faces for the convex solid that do not lie on the AABB boundary, let's call it F, and a list of pyramids, initial empty, called P. Then:

while F is not empty {
  for each vertex v of the AABB {
    for each face f in F {
      If v has line-of-sight to f (cross product test with face normal) {
        Build a pyramid p with base f and apex v
        Add p to P
        Remove f from F
        Add the other faces of p to F unless they lie on the AABB boundary
      }
    }
  }
}

Once this completes, you'll have a list of pyramids that includes all the volume of the AABB that is not in the solid - these can be combined into gestalt volumes by finding shared faces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top