# RegionErosion fails with Polygon

I would like to use RegionErosion to erode a Polygon. This example from the docs works:

With[{reg = StadiumShape[{{0, 0}, {2, 2}}, 2]},
Show@{
Region[
Style[reg, FaceForm[None], EdgeForm[Dashed]]
]
,
Region[
RegionErosion[reg, Line[{{0, 0}, {1, 1}}]]
]
}
]


However, changing the region from a "stadium shape" to a Polygon fails:

With[{reg = Polygon[{{0, 0}, {0, 2}, {2, 0}}]},
Show@{
Region[
Style[reg, FaceForm[None], EdgeForm[Dashed]]
]
,
Region[
RegionErosion[reg, Line[{{0, 0}, {1, 1}}]]
]
}
]


Both shapes are Regions:

And wrapping the Polygon in Region produces the same error.

I'm sure I'm missing something obvious. Thoughts?

• Maybe RegionErosion[reg, Line[{{0, 0}, {0, 1}, {1, 0}}]]. Commented Jun 26, 2023 at 20:00
• This returns EmptyRegion[1], the empty subset of R^1. This is surprising because our shapes are 2-dimensional, not 1, so I'd expect EmptyRegion[2] here. I see that RegionEmbeddingDimension returns 2 for the Polygon and the Line you suggested. Commented Jun 26, 2023 at 21:55
• You're right, Justin, there's something weird about that. Commented Jun 26, 2023 at 22:02

Maybe use RegionDilation for Line[-{{0, 0}, {1, 1}}].

With[{reg = Polygon[{{0, 0}, {0, 2}, {2, 0}}]},
Show@{Region[
Style[reg, FaceForm[Directive[Opacity[.2], Green]],
EdgeForm[Dashed]]],
Region[Style[RegionDilation[reg, Line[-{{0, 0}, {1, 1}}]],
FaceForm[Opacity[.5]], EdgeForm[]]]}]


• Hm, interesting idea, except I'm trying to erode the polygon, which should result in a smaller polygon. In your example, your green polygon has dilated into a larger blue shape. I am not sure that you can use RegionDilation to result in a smaller shape. Commented Jul 1, 2023 at 13:19
• @ConvexMartian RegionErosion[Rectangle[{0, 0}, {2, 2}], Line[{{0, 0}, {1, 1}}]] == RegionDilation[Rectangle[{0, 0}, {2, 2}], Line[-{{0, 0}, {1, 1}}]] Commented Jul 1, 2023 at 14:39
• @ConvexMartian Or your example With[{reg = StadiumShape[{{0, 0}, {2, 2}}, 2]}, Show@{Region[Style[reg, FaceForm[None], EdgeForm[Dashed]]], Region[RegionDilation[reg, Line[-{{0, 0}, {1, 1}}]]]}] Commented Jul 1, 2023 at 14:43