I have a (not necessarily convex) Polygon
, and want to create another Region
that can be seen as an extended boundary of the first polygon.
It should be quite simple; I tried it by creating a second polygon with 10% larger size, that I shift. It works for simple shapes such as squares, but it doesn't produce a boundary for different shapes.
myCoordinates = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
mypolygon = Polygon[myCoordinates];
dilatation = 1.1;
maxX = Max[myCoordinates[[;; , 1]]];
maxY = Max[myCoordinates[[;; , 2]]];
myCoordinatesLarge = dilatation*myCoordinates;
myCoordinatesLarge[[;; , 1]] -= (dilatation - 1)*maxX/2;
myCoordinatesLarge[[;; , 2]] -= (dilatation - 1)*maxY/2;
mypolygon2 = Polygon[myCoordinatesLarge];
RR = RegionIntersection[mypolygon2, mypolygon]
Show[Graphics[{LightBlue, EdgeForm[Gray], mypolygon, mypolygon2}], HighlightMesh[DiscretizeRegion[RR], 2]]
However, if my coordinates are
myCoordinates = {{0, 0}, {0, 1}, {3, 0}};
then I get this area without a boundary at the hypotenuse
The best would be to start from RegionCentroid[mypolygon]
and inflate the polygon without changing its RegionCentroid
, but I don't know how to do this.
Update: The method in the answers works for simple shapes such as squares or triangles, but if I have slightly more complex shapes, the result has no real boundary
myCoordinates = {{0, 0}, {0, 1}, {1, 1}, {2, 0}, {0.5, 0.5}};
mypolygon = Polygon[myCoordinates];
mypolygon2 = TransformedRegion[mypolygon, ScalingTransform[{2, 2}, RegionCentroid[mypolygon]]];
RR = RegionIntersection[mypolygon2, mypolygon];
Show[Graphics[{LightBlue, EdgeForm[Gray], mypolygon, mypolygon2}], HighlightMesh[DiscretizeRegion[RR], 2]]
mypolygon2 = Scale[ mypolygon, 1.5, RegionCentroid[ mypolygon ] ]
$\endgroup$