4
$\begingroup$

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}}]]
    ]
   }
 ]

works

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}}]]
    ]
   }
 ]

error

Both shapes are Regions:

regions

And wrapping the Polygon in Region produces the same error.

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

$\endgroup$
3
  • $\begingroup$ Maybe RegionErosion[reg, Line[{{0, 0}, {0, 1}, {1, 0}}]]. $\endgroup$ Jun 26, 2023 at 20:00
  • 2
    $\begingroup$ 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. $\endgroup$ Jun 26, 2023 at 21:55
  • $\begingroup$ You're right, Justin, there's something weird about that. $\endgroup$ Jun 26, 2023 at 22:02

1 Answer 1

4
$\begingroup$

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[]]]}]

enter image description here

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ Jul 1, 2023 at 13:19
  • $\begingroup$ @ConvexMartian RegionErosion[Rectangle[{0, 0}, {2, 2}], Line[{{0, 0}, {1, 1}}]] == RegionDilation[Rectangle[{0, 0}, {2, 2}], Line[-{{0, 0}, {1, 1}}]] $\endgroup$
    – cvgmt
    Jul 1, 2023 at 14:39
  • $\begingroup$ @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}}]]]}] $\endgroup$
    – cvgmt
    Jul 1, 2023 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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