Skip to main content

computational geometry - Separate boundaries of multiply connected region


I have a multiply connection two-dimensional region such as the following:


br = BoundaryDiscretizeGraphics@Graphics[Disk[#, 8/9] & /@ CirclePoints[9]]

Mathematica graphics


I am looking for a way to discard all inner "holes", i.e. get this:


enter image description here


In order to get this I was hoping to be able to separate the two boundaries of the region, then manually pick the outer one. What is a simple way to do this?



Answer



Here's an attempt to automate the selection of the outer boundaries with some undocumented properties. Here's a BoundaryMeshRegion with multiple holes and multiple outer boundaries:



g1 = Graphics[Table[Annulus[{x, 0}, {0.5 + x/20, 1}], {x, 0, 9, 3}]];
g2 = Graphics[Rectangle[{1.5, -0.3}, {7.5, 0.3}]];
br = RegionUnion[BoundaryDiscretizeGraphics /@ {g1, g2}]

enter image description here


The "BoundaryGroups" property groups the boundaries of connected regions, and it appears that the first element of each group is the outer boundary. (Pure conjecture of course, but that was the case for the limited number of tests I did).


bgps = br["BoundaryGroups"]
(* {{6, 2, 3, 4, 5}, {8, 7}, {1, 9}} *)

outer = bgps[[All, 1]]

(* {6, 8, 1} *)

I use another undocumented property, "IndexedBoundaryPolygons" to extract the polygons with those indices and construct a new region:


polys = br["IndexedBoundaryPolygons"][[outer]];

MeshRegion[MeshCoordinates[br], polys]

enter image description here


Comments