# circle using n-sided polygon

can anyone tell me how to draw a circle using an n-sided polygon i can not figure out the exact algorithm for it

jack

Noddy way of generating circle points:

for ( GLfloat Angle = StartAngle; Angle < EndAngle; Angle += nSteps )
{
GLfloat x = sin ( DEGTORAD(Angle) );
GLfloat y = cos ( DEGTORAD(Angle) );

glVertex3f ( x, y, 0.0f );
}

Here is a little program to create a polygon in a vertex list.
Enter sides which must be 3 or greater

3 = triangle
4 = sqaure
6 = hexagon
etc.
The more sides, the more it looks like a circle.

void buildquad( int sides, Point3F polygon[])
{
float angle, xangle;
float x, y, z;
float r;
int i;

r = 2.0f;
xangle = 3.1415927f / sides;

for (i=0; i <= sides; i++)
{
angle = xangle * i * 2;
polygon[i].xyz = r * cos( angle ); // X
polygon[i].xyz = r * sin( angle ); // Y
polygon[i].xyz = 0.0f; // Z
}
polygon[i] = polygon;
}

Originally posted by weedus:
[b]can anyone tell me how to draw a circle using an n-sided polygon i can not figure out the exact algorithm for it