10-14-2003, 07:41 PM

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)

please give me some idea

thanks

please give me some idea

thanks

View Full Version : How to draw regular polygon?

10-14-2003, 07:41 PM

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)

please give me some idea

thanks

please give me some idea

thanks

cg-hci_novice

10-14-2003, 07:56 PM

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

10-14-2003, 08:08 PM

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

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

10-14-2003, 08:29 PM

sorry~~

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

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

nexusone

10-15-2003, 10:26 AM

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];

}

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];

}

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.