Suppose I have two composite regions as follows:

body=RegionUnion[Cylinder[{{2.55, 0, 0}, {4.45, 0, 0}}, 0.55], 
     RegionDifference[Cylinder[{{2.5, 0, 0}, {4.5, 0, 0}}, 0.6], 
                      Cylinder[{{2.4, 0, 0}, {4.6, 0, 0}}, 0.5]]];
cutouts=RegionUnion[{Cuboid[{3.4, -1, -0.25}, {3.6, 1, 0.25}], 
                     Cuboid[{2.8, -1, -0.25}, {3.0, 1, 0.25}], 
                     Cuboid[{4.0, -1, -0.25}, {4.2, 1, 0.25}]}];

enter image description here

The first of these works fine. The second fails.

However, I can see the result using Graphics3D instead of RegionPlot3D:

enter image description here

The ultimate goal is to use the two regions with RegionDifference to make cutouts.


enter image description here


enter image description here

I can make it work by sequentially using RegionDifference with the individual Cuboids, but (at least conceptually) it seems like it should work with the union of them, and doing so would simplify the code significantly. Any suggestions?


Working with mesh regions (i.e., using DiscretizeRegion) instead of region primitives (e.g., Cuboid) will produce objects that can be rendered more easily.

body = RegionUnion[
    DiscretizeRegion @ Cylinder[{{2.55,0,0},{4.45,0,0}},0.55],
        DiscretizeRegion @ Cylinder[{{2.5,0,0},{4.5,0,0}},0.6],
        DiscretizeRegion @ Cylinder[{{2.4,0,0},{4.6,0,0}},0.5]
cutouts = RegionUnion[
    DiscretizeRegion @ Cuboid[{3.4,-1,-0.25},{3.6,1,0.25}],
    DiscretizeRegion @ Cuboid[{2.8,-1,-0.25},{3.0,1,0.25}],
    DiscretizeRegion @ Cuboid[{4.0,-1,-0.25},{4.2,1,0.25}]
RegionDifference[body, cutouts]

enter image description here

  • $\begingroup$ Hmmm. I was hoping to continue to use the primitives so that I could specify the polycount at the end rather than at earlier steps (such as during calls to DiscretizeRegion). I am playing with generating 3D regions for use in 3D printing, and debugging the forms at low polycounts, but then changing the polycount in one place at the end for production was extremely appealing. I'll see if I can make this approach work for me, though. $\endgroup$ – Kevin Ausman Nov 26 '19 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.