# How to get random polygons with points ordered mathematical positive?

I know how to get random polygons

poly = RandomPolygon[{"Convex", 3}, 10, DataRange -> {{0, 1}, {0, 1}}]


Only a subset is ordered positive

Select[poly, (pts = #[[1]];Cross[pts[[2]] - pts[[1]]] . (pts[[3]] - pts[[1]]) > 0) &]//Length (* 0( <10*)


But I don't know how to get polygons with points ordered in mathematical positive sense.

Any ideas? Thanks

• MeshPrimitives will consider the orientation.
Clear[polys];
polys=Polygon@MeshPrimitives[#, 1][[;; , 1]][[;; , 1]] & /@ poly
Select[polys, (pts = #[[1]];Cross[pts[[2]] - pts[[1]]] . (pts[[3]] - pts[[1]]) > 0) &]//Length


10

• Clever ot use MeshPrimitives, thank yo very much! Commented Apr 1 at 15:07
PositivelyOrientedPoints[{{a, b}, {c, d}, {e, f}}]


a d + b e + c f > b c + d e + a f

sol = FindInstance[
a d + b e + c f > b c + d e + a f && 0 < {a, b, c, d, e, f} < 1, {a,
b, c, d, e, f}, Reals, 10];

polypts = {{a, b}, {c, d}, {e, f}} /. sol // N;

PositivelyOrientedPoints /@ polypts


{True, True, True, True, True, True, True, True, True, True}

Graphics[{Polygon /@ polypts}, Frame -> True]


• thanks for your fast answer. I didn't know PositivelyOrientedPoints, probably because I'm using Mathematica v12.2... Commented Apr 1 at 14:54
• I am using v12.2.0 as well :) @UlrichNeumann
– Syed
Commented Apr 1 at 14:57
• Thanks again, couldn't find the command due to a typing error Commented Apr 1 at 15:04

In coo you get only positively oriented points. But when used in Polygon the coordinates order is modified by PolygonCoordinates according rules in CanonicalizePolygon.

poly = RandomPolygon[{"Convex", 3}, 10, DataRange -> {{0, 1}, {0, 1}}];
coo = If[PositivelyOrientedPoints[PolygonCoordinates[#]],
PolygonCoordinates[#], Reverse@PolygonCoordinates[#]] & /@ poly;

PositivelyOrientedPoints[#] & /@ coo

PositivelyOrientedPoints[PolygonCoordinates@#] & /@ (Polygon /@ coo)


{True, True, True, True, True, True, True, True, True, True}

{True, False, True, False, True, True, False, False, False, False}


Example of change of the order by PolygonCoordinates.

Polygon[{{1, 2}, {0, 0}, {0, 1}}] // PolygonCoordinates


--

{{0, 0}, {0, 1}, {1, 2}}