C#

Asked • 06/21/19

Calculate coordinates of a regular polygon's vertices?

I am writing a program in which I need to draw polygons of an arbitrary number of sides, each one being translated by a given formula which changes dynamically. There is some rather interesting mathematics involved but I am stuck on this probelm. How can I calculate the coordinates of the vertices of a regular polygon (one in which all angles are equal), **given only the number of sides**, and ideally (but not neccessarily) having the origin at the centre? For example: a hexagon might have the following points (all are `float`s): ( 1.5 , 0.5 *Math.Sqrt(3) ) ( 0 , 1 *Math.Sqrt(3) ) (-1.5 , 0.5 *Math.Sqrt(3) ) (-1.5 , -0.5 *Math.Sqrt(3) ) ( 0 , -1 *Math.Sqrt(3) ) ( 1.5 , -0.5 *Math.Sqrt(3) ) My method looks like this: void InitPolygonVertexCoords(RegularPolygon poly) and the coordinates need to be added to this (or something similar, like a list): Point[] _polygonVertexPoints; I'm interested mainly in the algorithm here but examples in C# would be useful. I don't even know where to start. **How should I implement it? Is it even possible?!** Thank you.

1 Expert Answer

By:

Tanner G. answered • 08/18/23

Tutor
New to Wyzant

Well-Rounded CS Tutor with Extensive C# Knowledge

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.