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$
2
  • 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
    Commented Feb 24, 2020 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$ Commented Feb 24, 2020 at 21:55

0

Your Answer

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

Browse other questions tagged or ask your own question.