# Thread: How to draw regular polygon?

1. ## How to draw regular polygon?

I don't know how to calculate the vertex out in order to draw n side polygon when the user enter a number(ie n)

thanks

2. ## Re: How to draw regular polygon?

Is it possible to use a for loop around glVertex within a glBegin/End block for what you are doing?

3. ## Re: How to draw regular polygon?

I would like to caculate the vertex of regular polygon

here is the equation I found

vi = ( (R cos (2ð(i-1)/N)), (R sin (2ð(i-1)/N)) ) for i = 1, 2, ... N.

but I cannot find any function to implement the pi, sine and cosine function

4. ## Re: How to draw regular polygon?

sorry~~
I think i ask an stupid question. It should be found in programming language

5. ## Re: How to draw regular polygon?

I wrote a little routine that would produce a list of vertex points, based on the number of sides inputed.

n = 3 = triangle
n = 4 = square
etc.
With enought points start to look 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[0] = r * cos( angle ); // X
polygon[i].xyz[1] = r * sin( angle ); // Y
polygon[i].xyz[2] = 0.0f; // Z
}
polygon[i] = polygon[0];

}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•