1
$\begingroup$

The code

Polygon[{{0,0},{3,0},{3,3},{1,3},{1,1},{2,2},{2,1},{0,1}}]

produces, according to Mathematica, a disconnected polygon with 0 area. The vertex {1,1} coincides with an edge it is not incident to: it is degenerate. Regardless, I'm looking to get a MeshRegion from it. Even attempting to construct meshes from the more explicitly defined

Polygon[{{0,0},{3,0},{3,3},{1,3},{1,1},{0,1}}->{{1,1},{2,1},{2,2}}]

fails. PolygonDecomposition does well for other degeneracies (i.e. handling 1-dimensional parts of shapes), but not this kind. There may be an easier way to create meshes from path data I'm not aware of. I want to create regions for arbitrary closed paths, possibly with coinciding vertices and edges, so manually creating the proper region is unsatisfactory (e.g.

RegionUnion[Polygon[{{0,0},{0,1},{2,1},{2,2},{3,3},{3,0}}],Polygon[{{1,1},{1,3},{3,3}}]]

). Detect and fix invalid polygon has outdated (and even so not applicable) solutions. How to decompose a self intersecting polygon into simple polygons? comes closer with Graphics`PolygonUtils`SimplePolygonPartition, but still outputs incomplete partitions.

$\endgroup$
3
  • 2
    $\begingroup$ DiscretizeGraphics[Polygon[{{0, 0}, {3, 0}, {3, 3}, {1, 3}, {1, 1}, {2, 2}, {2, 1}, {0, 1}}]] works fine. $\endgroup$ – J. M.'s torpor Feb 24 at 0:52
  • $\begingroup$ Should I add a self answer? $\endgroup$ – Adam Feb 24 at 20:03
  • $\begingroup$ I will upvote your answer if you do so. $\endgroup$ – J. M.'s torpor Feb 25 at 2:06
1
$\begingroup$

From the documentation,

PolygonDecomposition gives a Polygon consisting of a union of polygons with disjoint interiors, but boundaries may overlap.

Technically, the polygon in question has a decomposition into interior-disjoint polygons, but it happens not to be treated that way (Mathematica's documentation seems to mean that adjacent pieces in a decomposition share edges). Instead, its treated like

Polygon[{{0,0},{3,0},{3,3},{1,3},{1,.9},{2,2},{2,1},{0,1}}]

where the vertex {1,.9} is on the interior. It turns out CanonicalizePolygon is unhappy with interior vertices (and coinciding vertices and edges) as well. Turning away from polygons and towards MeshRegion, we find

MeshRegion is typically created using functions such as DelaunayMesh, DiscretizeGraphics, and DiscretizeRegion.

DiscretizeRegion approximates shapes in steps, and apparently fills the gap entirely. DiscretizeGraphics, as J.M.'s ennui reveals, succeeds. DiscretizeRegion DiscretizeGraphics

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.