Jump to content
  • Advertisement
Sign in to follow this  
iedoc

circle

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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:


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 this post


Link to post
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;
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}

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!