3
$\begingroup$

I make two regions and then find I can't combine them using RegionUnion. Here are the two regions.

r1 = Region@RegionDifference[
    RegionDifference[Cylinder[{{0, 0, 0}, {20, 0, 0}}, 6], 
     Cuboid[{0, 5, -6}, {20, 6, 6}]],
    Cuboid[{0, -6, -6}, {20, -5, 6}]
    ];
r2 = Region[Cylinder[{{20, 0, 0}, {28.5, 0, 0}}, 1/2]];
{r1, r2}

Mathematica graphics

Now I check their dimensions and plot them using Show.

    Show[r1, r2, Axes -> True, AxesLabel -> {"x", "y", "z"}, 
 Boxed -> True]

Mathematica graphics

So far so good. Now I attempt to combine them using RegionUnion and then plot them over the same dimensions as I used in the Show

r3 = RegionUnion[r1, r2];
Region[r3, PlotRange -> {{0, 30}, {-5, 5}, {-5, 5}}, Axes -> True, 
 AxesLabel -> {"x", "y", "z"}, Boxed -> True]

Mathematica graphics

All I have is a cuboid at one end of my plot.

What's going wrong? Version 11.3

Edit

@N.J.Evans suggested I try a simpler region. It did't work for him in Version 11.2.

r0 = Region[Cuboid[{15, -5, -5}, {20, 5, 5}]]

Mathematica graphics

Show[r0, r2]

Mathematica graphics

r4 = RegionUnion[r0, r2];
Region[r4]

Mathematica graphics

So that worked in Version 11.3. Looks like we have different problems in different versions.

$\endgroup$
7
  • $\begingroup$ Would it be acceptable to work with discretized regions in your application? If so, look into DiscretizeRegion. $\endgroup$
    – MarcoB
    Feb 25, 2019 at 19:23
  • $\begingroup$ @Hugh, that's better than what I got! I'm on 11.2 and I ran your code and got several errors when execution made it to r3, and then my CPU started working real hard and I had to kill the kernel. Maybe some kind of bug? I reduced it to the union of a cylinder and a cuboid and it still went crazy. $\endgroup$
    – N.J.Evans
    Feb 25, 2019 at 19:30
  • $\begingroup$ @MarcoB Thanks, but is there an easy way to join several regions after they have been discritised? Must I make one region and then discritise? $\endgroup$
    – Hugh
    Feb 25, 2019 at 19:31
  • $\begingroup$ @N.J.Evans Looking at a simpler union is a good idea. I will try. $\endgroup$
    – Hugh
    Feb 25, 2019 at 19:37
  • $\begingroup$ @Hugh I think Region function is meant for visualization purposes and you can drop it from inside RegionUnion and friends. $\endgroup$
    – Pinti
    Feb 26, 2019 at 7:51

1 Answer 1

5
$\begingroup$

Note that this is only an issue with the display -- the region itself is still correct. We can see this by sampling a bunch of random points:

Graphics3D[{PointSize[Tiny], 
  Point[RandomPoint[r3, 100000, {{0, 30}, {-5, 5}, {-5, 5}}]]}, Boxed -> False]

enter image description here

As a workaround, you can discretize then perform boolean operations:

r1 = Fold[RegionDifference, BoundaryDiscretizeRegion /@ {Cylinder[{{0, 0, 0}, {20, 0, 0}}, 6], 
  Cuboid[{0, 5, -6}, {20, 6, 6}], Cuboid[{0, -6, -6}, {20, -5, 6}]}];

r2 = BoundaryDiscretizeRegion[Cylinder[{{20, 0, 0}, {28.5, 0, 0}}, 1/2]];

r3 = RegionUnion[r1, r2]

enter image description here

$\endgroup$
1
  • $\begingroup$ Yes this works well. Thank you. Clearly a plotting problem and working with BoundaryDiscretizeRegion gives a workaround. $\endgroup$
    – Hugh
    Feb 26, 2019 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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