draw a circle

Started by
6 comments, last by dennizzz 20 years, 3 months ago
i wonder if there is an easy way of drawing a circle with help of the sin cos commands?
Advertisement
Sorry, but ever heard of Google?

x = cos(d) * r;
y = sin(d) * r;

d is in radians unless told otherwise.




"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
yeah i have figuered that out... but I can''t get anything on the screen...

anyone have a nice example...?
well, instead of that, u could go to the tutorials section, look at the tutorial on quadrics, it will show that to make a circle, u can just use the disc funcion and not put a hole in the middle
- relpats_eht
Crispy pretty much summed it all up.

const double deltaTheta = 0.1;const double r = 2.0;glBegin(GL_LINE_STRIP)for(double theta=0; theta < 2_PI; theta += deltaTheta){     glVertex3f(r * cos(theta), r * sin(theta), 0);}glEnd();


Want a disk? Use a triangle fan instead of a line strip.
thanks... that works nice
i''m now trying to make a nice tunnel of my circles...

just doing a loop and translating the circles... but i cant get a surface between the circles...

tried with the (GL_TRIANGLE_STRIP) but it doesn''t work...

any example?
You can use triangle strips here, but using triangles or even quads would be easier.

const double deltaTheta = 0.1;const double r = 2.0;const float SectionLength = 2.0f;int NumCircles = 10;for(int i = 0; i < NumCircles - 1; i++){glPushMatrix();glTranslatef(0, 0, i * SectionLength);glBegin(GL_QUADS)for(double theta=0; theta < 2_PI; theta += deltaTheta){     glVertex3f(r * cos(theta), r * sin(theta), 0);glVertex3f(r * cos(theta + deltaTheta), r * sin(theta + deltaTheta), 0);glVertex3f(r * cos(theta + deltaTheta), r * sin(theta + deltaTheta), SectionLength);glVertex3f(r * cos(theta), r * sin(theta), SectionLength);}glEnd();glPopMatrix();}


Haven''t tested the code, but this should give you a straight coridor the length of NumCircles * 2.0f units along the positive z axis. If you want to add bends to the tunnel, try to do some tweaking yourself - copy-pasting all of the code isn''t fun either, is it now?




"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

This topic is closed to new replies.

Advertisement