circle
you might think this is a stupid question, but how do you make a plane circle, like a square, but just a circle?
Mathematically: (x-xcenter)2+(y-ycenter)2 = radius2.
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:
So, it's really an n-sided regular polygon but, with enough sides, it's indistinguishable from a circle.
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.
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;
radius = 2;
for (int i=0; i<12; i++) {
int x = sin(i*degree)*radius;
int y = cos(i*degree)*radius;
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}
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;
radius = 2;
for (int i=0; i<12; i++) {
int x = sin(i*degree)*radius;
int y = cos(i*degree)*radius;
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}
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement