# Fix (decompose) Degenerate Polygon (vertex coincides with edge)

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 GraphicsPolygonUtilsSimplePolygonPartition, but still outputs incomplete partitions.

• DiscretizeGraphics[Polygon[{{0, 0}, {3, 0}, {3, 3}, {1, 3}, {1, 1}, {2, 2}, {2, 1}, {0, 1}}]] works fine. Commented Feb 24, 2021 at 0:52
Commented Feb 24, 2021 at 20:03
• I will upvote your answer if you do so. Commented Feb 25, 2021 at 2:06

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.