Public Group

# circle

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

## Recommended Posts

you might think this is a stupid question, but how do you make a plane circle, like a square, but just a circle?

##### Share on other sites

Graphically, you have to break it down into a number of segments: OpenGL doesn't have a function to render curves (aside from NURBS, but that's a separate issue), and I assume DX doesn't either. So you would probably do something like:

void draw_circle(float radius, unsigned int sides){   float delta_angle = 6.283185 / sides;   float angle = 0;   glBegin(GL_LINE_LOOP);   for (unsigned int index = 0; index < sides; ++index, angle+= delta_angle)      glVertex2f(radius*cos(angle), radius*sin(angle));   glEnd();}

So, it's really an n-sided regular polygon but, with enough sides, it's indistinguishable from a circle.

##### Share on other sites
its like a pizza. a square only has 4 verts, but as you keep adding more the shape becomes more and more like a circle

you also need to use sin and cos, but they are easy you just get the sin and cos of your angls and multiply them by your radius
so to make a sircle with 12 points you would:

degree = 360/12;
for (int i=0; i<12; i++) {
PutDot(x,y);
}

void PutDot(int x, int y) {
//...
}

if PutDot did anything it would put 12 dots in a circle exactly 2ish away from {0,0}

##### Share on other sites
Just a quick note to prevent confusion
Laserus: You are using sin and cos with degree values. If you are using the functions from math.h you will first need to convert the angles to radians by multiplying each angle by pi/180.

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633331
• Total Posts
3011399
• ### Who's Online (See full list)

There are no registered users currently online

×