# regions – RegionDifference does not work with a single cuboid and a large number of built-in cylinders

I'm trying to create a cuboid with embedded hollow cylindrical regions. This seems to work fine when I use a relatively small number of cylinders (about 20) but do not work when I use a large number of cylinders (usually more than 40). In my real application, I need more than 100.

Any help would be greatly appreciated!

Attached, find the codes that I used:

``````Clear[rcoord, matr, pts1, pts2, cyl3, regCyl3, matDiff]
(* create a list of 3 real pseudo-random between 0 and 1 *)
rcoord: = RandomReal[1., 3]
(* generates the filled RVE cuboid *)
scl2 = 0.1;
matr = BoundaryDiscretizeGraphics[
Cuboid[{0, 0, 0} + {scl2, scl2, scl2}, {1, 1, 1} - {scl2, scl2,
scl2}]];

(* generate a list of random cylinders in Cuboid *)
cylTot = 100; (* total number of random cylinders *)
cylRem = 20; (* number of random cylinders to remove cuboid *)
pts1 = table[rcoord, {cylTot}];
pts2 = table[rcoord, {cylTot}];
cyl3 = Table[
Length[pts1]}]; (* list of all cylinders *)
regCyl3 =
Table[BoundaryDiscretizeGraphics[cyl3[BoundaryDiscretizeGraphics[cyl3[BoundaryDiscretizeGraphics[cyl3[BoundaryDiscretizeGraphics[cyl3[[i]]]{i, 1,
Length[cyl3]}]; (* list of all cylindrical regions *)

(* generate the hollow RVE cuboid by removing random cylinders from
Cuboid *)
(* works when I delete only a small number, usually less than
40 cylinders *)
matDiff =
RégionDifférence[matr,
regCyl3[]]; (* remove the first cylnderRegion from Cuboid *)
matDiff = Fold[(RegionDifference[#1, #2]) And
matDiff,
regCyl3[[2 ;;
cylRem]]]; (* Remove the rest of cylnderRegions from Cuboid *)
HighlightMesh[matDiff, Style[2, Opacity[0.5]]]RegionPlot3D[matDiff, PlotStyle -> Directive[Yellow, Opacity[0.5]],
Mesh -> None]
``````

But I receive error messages when I use a large number of cylinders:

``````(* create a new derivative region by removing Cuboid's random cylinders
*)
(* Does not work when I try to remove a large number of cylinders,
usually more than 40 *)
Clear[matDiffAll, cylRemAll];
cylRemAll = 60;
matDiffAll =
RégionDifférence[matr,
regCyl3[]]; (* remove the first cylnderRegion from Cuboid *)
matDiffAll = Fold[(RegionDifference[#1, #2]) And
matDiffAll,
regCyl3[[2 ;;
cylRemAll]]]; (* Remove the rest of cylnderRegions from Cuboid *)
HighlightMesh[matDiffAll, Style[2, Opacity[0.5]]]RegionPlot3D[matDiffAll, PlotStyle -> Directive[Yellow, Opacity[0.5]],
Mesh -> None]
``````

Posted on