I have some properties defined by the user, and then I want use them to automatically generate a regular polygon. The properties are centre x, centre y, radius and number of vertices. I would like to know how to calculate the x and y coordinates of all vertices of a regular polygon. I've already tried to do as Calculate coordinates of a regular polygon's vertices discussion. But it always gives me thw wrong coordinates. My current code is as follows (C++):
#define DOUBLE(a) ((a)*(a))
...
if(radius <= 0 || vertices < 3)
return NULL;
Polygon* poly = new Polygon;
double angle = DOUBLE(M_PI) / vertices;
for(long i = 0; i < vertices; i++)
{
double a = (angle * i);
poly->add(centerX + radius * cos(a), centerY + radius * sin(a));
}
return poly;