algorithm - How to represent / Modify 3d solids -


in program have cubes (simple, xyz location, xyz size). want bo able take 1 of these cubes , 'subtract' cube it.

so question, generic data structure represent resulting 3d object, , kind of algorithm used subtract 3d solid another?

this pretty general question , depends on want know solid , how fast want know it. assuming want membership tests, might work (psuedocode):

class solid {     solid solids = [] // each solid has list of solids                         // have been subtracted it.                            abstract method containedinself(point) {         // vary 1 type of solid     }       method contains(point) {         if !containedinself(point) return false;         else {             solid in solids {  // loop on contained solids                 if solid.contains(point) return false;                  // point contained in solid has been subtracted             }             // know point contained not contained in             // that's been subtracted             return true;         }     }      method subtract(solid) {         solids.append(solid)     }   } 

this has advantage of allowing composite subtractions. example, can subtract solid a solid b , solid b solid c , work expected. example 3 spheres centered @ origin , radius(a) < radius(b) < radius(c), you'll points contained in a or contained in c not b.

you can also, example, subtract 2 dodecahedrons sphere , subtract cube. of course same subtracting sphere cube , adding 2 dodecahedrons in.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -