I'm trying to build an octree representing a volume which is originally described by a CSG (Constructive Solid Geometry) tree.
My original plan was to start with a big cube that contains the entire object and then test, for each of the eight sub-cubies, which ones are completely outside, which are completely inside the object, and which are both inside and outside. These "middle" cubies would then get recursively subdivided.
My problem may be stupid, but I can't devise a way to find the intersection of a cube and the CSG object, to be able to classify the cube as above.
My CSG structure is built from primitives such as cubes, spheres and cylinders (and maybe toruses in the future), with the boolean operations of union, intersection and subtraction.
Beside the explicit tree structure of the CSG, from its representation I also have a sort of distance function d(x,y,z)
that would tell me if the point (x,y,z)
is outside (>0) or inside (<0) the object.
How can I find if a cube intersect the object described by the CSG structure?