I am interested in generating 3D a joint BoundaryMeshRegion or a MeshRegion from different shapes and polygons. This works for RandomPolygon:
i):
r1 = BoundaryDiscretizeGraphics[
Graphics[RandomPolygon[15,
DataRange -> {{0.02, 0.08}, {-0.02, 0.04}}]]];
r2 = BoundaryDiscretizeGraphics[
Graphics[RandomPolygon[12,
DataRange -> {{0.00, 0.03}, {-0.02, 0.03}}]]]
bnd1 = RegionProduct[r1, MeshRegion[{{0.01}, {0.05}}, Line[{1, 2}]]];
bnd2 = RegionProduct[r2, MeshRegion[{{0}, {0.02}}, Line[{1, 2}]]];
un1 = RegionUnion[bnd1, bnd2];
Show[un1, Boxed->True, Axes->True]
I also wanted to include the shape of a country and combine it with a random polygon or another country shape a similar manner, which is possible as long as they are combined in 2D-state:
ii):
r3 = BoundaryDiscretizeGraphics[CountryData["Spain", "Shape"],
ImageSize -> Medium, Axes -> True]
r4 = BoundaryDiscretizeGraphics[
Graphics[RandomPolygon[15,
DataRange -> {{0.05, 0.3}, {-0.08, 0.08}}]]];
bnd3 = RegionUnion[r3, r4];
un2 = RegionProduct[bnd3, MeshRegion[{{0}, {0.02}}, Line[{1, 2}]]];
Show[un2, Boxed->True, Axes->True]
However, as soon as one tries to combine a generated 3D shape of a country with a generated 3D shape of the Polygon, the following output results:
iii):
bnd31 = RegionProduct[r3, MeshRegion[{{0.0}, {0.02}}, Line[{1, 2}]]];
r5 = BoundaryDiscretizeGraphics[
Graphics[RandomPolygon[8,
DataRange -> {{0.03, 0.12}, {-0.06, 0.06}}]]];
bnd32 = RegionProduct[r5, MeshRegion[{{0.015}, {0.03}}, Line[{1, 2}]]];
RegionUnion[bnd31, bnd32];
In some cases Mathematica crashes.
How would I solve this issue? My aim is to combine a 3D shape of a country with a 3D shape of RandomPolygon, so that both shapes have different heights with respect to each other. The volumes need to be connected with each other though (similarly to ii)), as I would like to apply a RegionMemberFunction in a later step.
The code for the 3D-shape generation was found here: How to extrude a 3D image from a binary 2D image
I am running on Mathematica 12.
Thank you for your help in advance!



bnd3? – Henrik Schumacher Aug 09 '19 at 14:41bnd3 = RegionUnion[r3, r4];; I have spotted the mistake you are reffering to in i), meant to be:un1 = RegionUnion[bnd1, bnd2];insteadun1 = RegionUnion[bnd2, bnd3];– Jeff71 Aug 09 '19 at 14:51bnd32is a nonconnectedBoundaryMeshRegionand the algorithmRegionUnionofBoundaryMeshRegions is somehow dependend on the hidden that each region is connected. Huge mess if you ask me. Unfortunately, I have no idea at the moment how to bypass this. Btw. the Boolean region tools in Mathematica are buggy also in many other ways. It is really frustrating. – Henrik Schumacher Aug 09 '19 at 14:56