# Regions and their combinations

I met stupid problems playing with combinations of simple 3D regions. Can anyboby explain what is wrong in my code?

I need to make a model for 3D-printing.

RegionPlot3D[{
Cuboid[{-3, -27, 0}, {-6, -50, 25}],
Cuboid[{-5, -41, 0}, {-20, -38, 25}],
Prism[{{-27, -38, 0}, {-19, -38, 0}, {-19, -45, 0}, {-27, -38,
25}, {-19, -38, 25}, {-19, -45, 25}}],
rg1,
Cuboid[{-3, 27, 0}, {-6, 50, 25}],
Cuboid[{-5, 41, 0}, {-20, 38, 25}],
Prism[{{-27, 38, 0}, {-19, 38, 0}, {-19, 45, 0}, {-27, 38,
25}, {-19, 38, 25}, {-19, 45, 25}}]},
PlotPoints -> 81,
Axes -> True, AxesLabel -> {"X", "Y", "Z"},
PlotRange -> {{-60, 60}, {-60, 60}, {0, 27}}]


where the rg1 is 3D-arc:

rg1=RegionIntersection[
RegionDifference[
Cylinder[{{0, 0, 0}, {0, 0, 25}}, 30],
Cylinder[{{0, 0, 0}, {0, 0, 25}}, 27]],
Cuboid[{-6, -30, 0}, {30, 30, 25}]
];


Generally, it looks like following:

However, I need the joint region to make the stl-file. Thus, I've tried the RegionUnion to combine the elements. However, it is not so easy:

Making the clamps, I found that simple

RegionUnion[
Cuboid[{-3, -27, 0}, {-6, -50, 25}],
Cuboid[{-5, -41, 0}, {-20, -38, 25}],
Prism[{{-27, -38, 0}, {-19, -38, 0}, {-19, -45,
0}, {-27, -38, 25}, {-19, -38, 25}, {-19, -45, 25}}]
]


produces an error-message:

RegionBounds::reg: Cuboid[{-3,-27,0},{-6,-50,25}] is not a correctly specified region.

Ok, I've tried following:

rc1=RegionUnion[
Region@Cuboid[{-3, -27, 0}, {-6, -50, 25}],
Region@Cuboid[{-5, -41, 0}, {-20, -38, 25}],
Region@Prism[{{-27, -38, 0}, {-19, -38, 0}, {-19, -45,
0}, {-27, -38, 25}, {-19, -38, 25}, {-19, -45, 25}}]
];
rc2 = RegionUnion[
Region@Cuboid[{-3, 27, 0}, {-6, 50, 25}],
Region@Cuboid[{-5, 41, 0}, {-20, 38, 25}],
Region@
Prism[{{-27, 38, 0}, {-19, 38, 0}, {-19, 45, 0}, {-27, 38, 25}, {-19, 38, 25}, {-19, 45, 25}}]
];


It works good, making the separate clamps like following without errors:

But when I try to combine the whole model I again met the errors: RegionPlot3D[{rg1, rc1, rc2}]

RegionPlot3D::nnregion: Region[BooleanRegion[#1||#2||#3&,{Cuboid[{-3,-27,0},{-6,-50,25}],Cuboid[{-5,-41,0},{-20,-38,25}],Prism[{{-27,-38,0},{-19,-38,0},{-19,-45,0},{-27,-38,25},{-19,-38,25},{-19,-45,25}}]}]] cannot be automatically discretized.

RegionPlot3D::invplotreg: {BooleanRegion[#1&&!#2&&#3&,{Cylinder[{{0,0,0},{0,0,25}},30],Cylinder[{{0,0,0},{0,0,25}},27],Cuboid[{-6,-30,0},{30,30,25}]}],Region[BooleanRegion[#1||#2||#3&,{<<1>>}]],Region[BooleanRegion[#1||#2||#3&,{Cuboid[{-3,27,0},{-6,50,25}],Cuboid[{-5,41,0},{-20,38,25}],Prism[{{-27,38,0},{-19,38,0},{-19,45,0},{-27,38,25},{-19,38,25},{-19,45,25}}]}]]} is not a valid region to plot.

RegionPlot3D::argr: RegionPlot3D called with 1 argument; 4 arguments are expected.

When I try the RegionUnion[rc1,rg1,rc2], it gives me following:

Region[
BooleanRegion[Or[#, #2, #3,
And[#4,
Not[#5], #6], #7, #8, #9]& , {
Cuboid[{-3, -27, 0}, {-6, -50, 25}],
Cuboid[{-5, -41, 0}, {-20, -38, 25}],
Prism[{{-27, -38, 0}, {-19, -38, 0}, {-19, -45, 0}, {-27, -38,
25}, {-19, -38, 25}, {-19, -45, 25}}],
Cylinder[{{0, 0, 0}, {0, 0, 25}}, 30],
Cylinder[{{0, 0, 0}, {0, 0, 25}}, 27],
Cuboid[{-6, -30, 0}, {30, 30, 25}],
Cuboid[{-3, 27, 0}, {-6, 50, 25}],
Cuboid[{-5, 41, 0}, {-20, 38, 25}],
Prism[{{-27, 38, 0}, {-19, 38, 0}, {-19, 45, 0}, {-27, 38, 25}, {-19,
38, 25}, {-19, 45, 25}}]}]]


but it does not produce a normal 3D-region.

What is wrong with these 3D primitives?

• Do they meet at an exact plane? Sometimes you have to mush the two regions into each other by a tiny bit. For example, if RegionUnion[{Cuboid[{0, 0, 0}, {1, 1, 1}], Cuboid[{0, 0, 1}, {1, 1, 2}]}] didn't work, you'd squash them together like this RegionUnion[{Cuboid[{0, 0, 0}, {1, 1, 1}], Cuboid[{0, 0, 0.9999}, {1, 1, 2}]}] By the way your first bit of code for the clamp worked for me on v12.1.1.0 and I got a correct looking Polyhedron object back, so you're probably experiencing a bug in an older version. . Commented Oct 7, 2020 at 10:58
• @flinty, as I understood, you mean the presence of the invisible gaps between pieces of Region? My code makes them touching without overlapping but without gaps too. May be the microgaps appears during the inner processing of the 3D primitives due to numerical errors, I don't know. Commented Oct 8, 2020 at 8:36
• No I mean even if they're touching perfectly without gaps it can go wrong. You should make them touch and overlap by a very tiny amount (which you may need to experiment with). Commented Oct 8, 2020 at 12:13