# How to create a simple polygon

I am trying to create a simple (with no self-intersections) polygon having four given points as vertices, for example to calculate its perimeter later. However, it seems there is nothing for this basic functionality. For instance, I would like to create a square given the following sequence of four points (irrespective to their order) in the following example, but I cannot "force" the software to create a simple polygon:

Polygon[{{0,0},{1,1},{1,0},{0,1}}]


I would like that the software to "arrange" the sequence of points to create a simple polygon, that is, in this specific case, a square (WindingPolygon does not work for this purpose).

• You might be interested in CirclePoints as well to generate the vertices of a regular polygon. Commented Nov 18, 2020 at 17:35

If you already have the list of coordinates, then FindCurvePath should be able to re-order them for you:

pts = {{0, 0}, {1, 1}, {1, 0}, {0, 1}};
Graphics@ Polygon[pts]


Graphics@Polygon@pts[[First@FindCurvePath[pts]]]


• Thank you very much. It works for plotting the simple polygon, but I do not understand why it does not work in this simple optimization problem, where we look for the simple 4-gon with maximal perimeter in the region of the unit disc: NMaximize[{Perimeter[Polygon[{{a, b}, {c, d}, {e, f}, {g, h}}[[First[FindCurvePath[{{a, b}, {c, d}, {e, f}, {g, h}}]]]]]], a^2+b^2<=1, c^2+d^2<=1, e^2+f^2<=1, g^2+h^2<=1}, {a,b,c,d,e,f,g,h}] . How can we arrange the NMaximize command argument in your opinion? Commented Nov 18, 2020 at 20:25
• @PenelopeBenenati I don't think FindCurvePath would have any way of working symbolically; I think you might want to hide it behind a target function perhaps, with inputs protected by ?NumericQ. Commented Nov 18, 2020 at 21:00
• Could you please provide me an example of he use of "?NumericQ" within this specific context (maximizing the perimeter of a simple polygon within a certain region of the plane)? Thank you in advance! PS: I am open to completely alternative solution for formalizing this problem. Commented Nov 19, 2020 at 0:18

You just need to sort your points according to an increase of the bypass angle.

Graphics@Polygon[
SortBy[
{{0, 0}, {1, 1}, {1, 0}, {0, 1}},
Arg[First@# + I Last@#] &
]]


Actually, the sorting function can be different just keep the bypass angle increasing...

• I think I know what you mean, but I'm not familiar with the term "bypass angle". Can you add a link perhaps? Commented Nov 18, 2020 at 17:50
• @MarcoB, May be I've used the wrong English term. I mean that if you have the set of points, than you can draw the convex polygon by paving the path from one point to another only if the set is ordered by the special way. The main requirement for points sorting is permanent increase (or decrease) of the winding angle of vector connecting the center of the figure and these points. Commented Nov 19, 2020 at 7:34

Toward the problem in the comment.

For arbitrary 4 points in Disk[],the 4 points not always construct a simple region.

SeedRandom[9876543]
pts = RandomPoint[Disk[],4];

{{Graphics[{Point[pts], Circle[], Orange, Opacity[0.5],
Polygon[pts]}],
Perimeter[
Polygon[pts]]}, {Graphics[{Point[pts], Circle[], Orange,
Opacity[0.5], DelaunayMesh[pts]}],
Perimeter[DelaunayMesh[pts]]}} // Grid


Although the NMaximize Area problem is easy to do, the Perimeter problem is still not easy to handle.

sol = NMaximize[{Area[Polygon[{x, y, z, w}]],
x ∈ Disk[] && y ∈ Disk[] &&
z ∈ Disk[] && w ∈ Disk[]}, {x, y, z, w}];
pts = {x, y, z, w} /. Last@sol;
Graphics[{Brown, Polygon[pts], FaceForm[], EdgeForm[Cyan], Disk[]}]


NMaximize[{Perimeter[Polygon[{x, y, z, w}]],
x ∈ Disk[] && y ∈ Disk[] && z ∈ Disk[] &&
w ∈ Disk[]}, {x, y, z, w}]

vertices[n_] := Table[{Cos[(2 \[Pi] k)/n], Sin[(2 \[Pi] k)/n]}, {k, Range[0, n]}];
polygon[n_] := Graphics@Line[vertices[n]];

GraphicsRow[Table[polygon[n], {n, Range[3, 7]}]]


vertices2[n_] :=

• You may care to add that the built-in CirclePoints does the same thing; you can set starting angle as well. Commented Nov 18, 2020 at 17:49