3
$\begingroup$

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

$\endgroup$

3 Answers 3

3
$\begingroup$
  • 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

$\endgroup$
1
  • $\begingroup$ Clever ot use MeshPrimitives, thank yo very much! $\endgroup$ Commented Apr 1 at 15:07
3
$\begingroup$
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]

enter image description here


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

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}}
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.