In my program I have some cubes (simple, xyz location, xyz size). I want bo be able to take one of these cubes and ‘Subtract’ another cube from it.
So my question, what is a good generic data structure to represent the resulting 3d object, and what kind of algorithm is used to subtract a 3d solid from another?
This is a pretty general question and depends on what you want to know about the solid and how fast you want to know it. Assuming that you only want membership tests, this might work (psuedocode):
This has the advantage of allowing composite subtractions. For example, you can subtract solid
Afrom solidBand then solidBfrom solidCand it will work as expected. For example with three spheres centered at the origin andradius(A) < radius(B) < radius(C), you’ll get points that are contained inAor contained inCbut notB.You can also, for example, subtract a two dodecahedrons from a sphere and then subtract that to a cube. Which is of course the same as subtracting the sphere from a cube and adding two dodecahedrons back in.