I don't understand why, in the example below, PolygonCoordinates
seems unable to correctly extract the summits of a rectangle in the "right" order so we can reconstruct the same shape:
Rectangle[{-1,-1},{1,0}]
PolygonCoordinates[%]
Polygon[%]
Producing:
Rectangle[{-1,-1},{1,0}] {{-1,-1},{-1,0},{1,-1},{1,0}}
Obviously, the resulting polygon is not a rectangle. Why? How to fix that?
FWIW, there is an old, unanswered, and very similar question here:
Order of PolygonCoordinates[] is undefined in Mathematica 12?
Rectangle[{-1, -1}, {1, 0}] // CanonicalizePolygon // Normal // First
gives the coordinates in the right order. It works in this case too. The use ofFirst
can be found in the documentation ofPolygonCoordinates
chapter "properties & Relation", though I'm not conviced that it is reliable. $\endgroup$CanonicalizePolygon
reliably produces a polygon whose submits are in the original shape order. There are even an example in the doc about converting aRectangle
to aPolygon
. It'sPolygonCoordinates
that ignore the original vertice order. $\endgroup$