I am interested in generating 3D a joint BoundaryMeshRegion or a MeshRegion from different shapes and polygons. This works for RandomPolygon:


r1 = BoundaryDiscretizeGraphics[
    DataRange -> {{0.02, 0.08}, {-0.02, 0.04}}]]];
r2 = BoundaryDiscretizeGraphics[
    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]

Unified Region of two 3D generations of RandomPolygon

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:


r3 = BoundaryDiscretizeGraphics[CountryData["Spain", "Shape"], 
  ImageSize -> Medium, Axes -> True]
r4 = BoundaryDiscretizeGraphics[
    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]

Unified Region of two 3D generations of RandomPolygon and a countriyshape respectively

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:


bnd31 = RegionProduct[r3, MeshRegion[{{0.0}, {0.02}}, Line[{1, 2}]]];
r5 = BoundaryDiscretizeGraphics[
    DataRange -> {{0.03, 0.12}, {-0.06, 0.06}}]]];
bnd32 = RegionProduct[r5, MeshRegion[{{0.015}, {0.03}}, Line[{1, 2}]]];
RegionUnion[bnd31, bnd32];

Output of iii)

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!

  • $\begingroup$ Would you please give also the definition of bnd3? $\endgroup$ – Henrik Schumacher Aug 9 at 14:41
  • $\begingroup$ @HenrikSchumacher bnd3 = RegionUnion[r3, r4]; ; I have spotted the mistake you are reffering to in i), meant to be: un1 = RegionUnion[bnd1, bnd2]; instead un1 = RegionUnion[bnd2, bnd3]; $\endgroup$ – Jeff71 Aug 9 at 14:51
  • $\begingroup$ Jeff, did you know that can edit your post? =) $\endgroup$ – Henrik Schumacher Aug 9 at 14:54
  • $\begingroup$ @HenrikSchumacher Just realized and did that. Sorry for the confusion. :D $\endgroup$ – Jeff71 Aug 9 at 14:56
  • 2
    $\begingroup$ Oh my, that's a nasty problem. You should definitely tell support about it. There is a chance that this will get fixed in the next four to five years... ;) I think the problem is that bnd32 is a nonconnected BoundaryMeshRegion and the algorithm RegionUnion of BoundaryMeshRegions 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. $\endgroup$ – Henrik Schumacher Aug 9 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.