# RegionDifference for Cylinder and Cuboid

I wish to use RegionDifference to take a cube shape out of a cylinder. First I make the cylinder and cube and combine them in RegionUnion.

reg1 = Cylinder[{{0, 0, 0}, {10, 0, 0}}, 0.5];
reg2 = Cuboid[{5, 0, 0}, {10, 1, 1}];
Region[RegionUnion[reg1, reg2], Axes -> True]


So this looks good so far. Now I wish to take the cuboid out of the cylinder leaving a notch in the cylinder. I try

reg = RegionDifference[reg1, reg2];
Region[reg, Axes -> True, PlotRange -> All]


My cylinder is chopped off short and given a bad end (away from the subtraction). Is there a workaround?

Version 11.3 for windows.

• Wow, that's really weird. Please contact support. Honestly, I am quite disappointed with the almost nonexistent usability of the BooleanRegion facilities. – Henrik Schumacher Mar 14 at 18:37
• I have sent it off to support.I agree about being fed up. Second time in two days you have had to help me out -for which I am very grateful. – Hugh Mar 14 at 19:24

Please note the RegionBounds:

reg1 = Cylinder[{{0, 0, 0}, {10, 0, 0}}, 0.5];
reg2 = Cuboid[{5, 0, 0}, {10, 1, 1}];
reg = RegionDifference[reg1, reg2];

bounds = RegionBounds@reg;
Region[reg, Axes -> True, PlotRange -> bounds]


• Whoa. Why did PlotRange -> All not work? Anyways, good job! – Henrik Schumacher Mar 14 at 21:43
• I put in PlotRange All because I wondered if it was a plotting problem. Are there known issues with PlotRange? – Hugh Mar 14 at 22:31
• @Hugh How Mathematica works is probably only known to the developers. For the user remains only trial and error. But I have already encountered this problem earlier. You have sent it off to support, that's ok. – rmw Mar 15 at 9:05

This seems to be a viable workaround although it is a shame that we have to discretize the cylinder that early.

reg1 = BoundaryDiscretizeRegion[Cylinder[{{0, 0, 0}, {10, 0, 0}}, 0.5], MaxCellMeasure -> 0.001];
reg2 = BoundaryDiscretizeRegion[Cuboid[{5, 0, 0}, {10, 1, 1}]];
reg = RegionDifference[reg1, reg2]


As a rule of thumb, I would strongly discourage applying boolean operations to graphics primitives and everything else which is neither a MeshRegion nor a BoundaryMeshRegion.

• @JasonB. Thank you for the edit. That was an error that I make too often... – Henrik Schumacher Mar 14 at 21:41