2
$\begingroup$

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

Not a rectangle

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?

$\endgroup$
  • 1
    $\begingroup$ Rectangle[{-1, -1}, {1, 0}] // CanonicalizePolygon // Normal // First gives the coordinates in the right order. It works in this case too. The use of First can be found in the documentation of PolygonCoordinates chapter "properties & Relation", though I'm not conviced that it is reliable. $\endgroup$ – andre314 Feb 24 at 19:34
  • $\begingroup$ Thanks for the comment André. I've done some tests this afternoon. Apparently CanonicalizePolygon reliably produces a polygon whose submits are in the original shape order. There are even an example in the doc about converting a Rectangle to a Polygon. It's PolygonCoordinates that ignore the original vertice order. $\endgroup$ – Sylvain Leroux Feb 24 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.