Tanner G. answered 08/18/23
Well-Rounded CS Tutor with Extensive C# Knowledge
A good place to start is by examining the properties of a regular polygon:
- The angle between every vertex will be equal.
- The angles within a regular polygon will all sum to 2*PI radians (360 degrees). This is important as combined with the first property, will allow us to find the angle for each vertex given the number of vertices.
- All polygons have a number of vertices equal to the number of sides they have. This will allow us to finally determine the number of vertices, and with it, the angle between each vertex.
With the angle of each vertex, we can use the trigonometric functions Cosine and Sine to determine the X and Y coordinates respectively! Putting these into code, we can break this into three steps:
Note that this will always have a vertex directly to the right. To make all the shapes "standing" as it appears in the coordinates you provide, you can add an offset to "vertexAngle." To make it stand upright, add MathF.PI / 2.