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 som
The number of points equals the number of sides.
The angle you need is angle = 2 * pi / numPoints
.
Then starting vertically above the origin with the size of the polygon being given by radius
:
for (int i = 0; i < numPoints; i++)
{
x = centreX + radius * sin(i * angle);
y = centreY + radius * cos(i * angle);
}
If your centre is the origin then simply ignore the centreX
and centreY
terms as they'll be 0,0.
Swapping the cos
and sin
over will point the first point horizontally to the right of the origin.