#### Archived

This topic is now archived and is closed to further replies.

# draw a circle

This topic is 5243 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i wonder if there is an easy way of drawing a circle with help of the sin cos commands?

##### Share on other sites
Sorry, but ever heard of Google?

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

d is in radians unless told otherwise.

##### Share on other sites
yeah i have figuered that out... but I can''t get anything on the screen...

anyone have a nice example...?

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
thanks... that works nice

##### Share on other sites
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?

##### Share on other sites
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?

• 10
• 19
• 14
• 19
• 15