View Full Version : polygon approximation

11-18-2005, 03:12 AM
polygon approximation of a circle algorithm

This code does not print anything on the screen
(I mean the glVertex2i didn't print when it was not commented),
it must depend on that the size of number : -r*sin(2*i*PI/seg) is like a 100 millions or so

But this is the formula I got
Do you know how to improve this code ...?

Regards OGforever

//Draws a circle as approximation of linesegments
void polyCircle(int xc, int yc , int r, int seg)
int i, x, y ;
float xf, yf ;

glBegin(GL_POINTS) ;
glColor3f(0, 1.0, 0) ;
for(i = 0 ; i < seg ; i++)
glVertex2i(i, 24) ;
printf("Polypoly") ;

printf("printing x %d", -r*sin(2*i*PI/seg)) ;
yf = r*cos(2*i*PI/seg) ;
glVertex2i(xc + (int)xf, yc - (int)yf) ;


11-18-2005, 03:51 AM
Algorithms for circles are pretty easy and can be found in any book about math, otherwise you can find it in the archive of this forum or using google.


11-18-2005, 05:49 AM
you assign a value for yf, but none for xf. and
you should use a cast operator for i and seg
when using it in sin/cos.

xf = r*cos(2*(float)i*PI/(float)seg) ;
yf = r*sin(2*(float)i*PI/(float)seg) ;