I am completely stuck on how to draw a circle in c++ any advice?

Printable View

- 07-22-2003TheShaggmeisterDraw a circle?
I am completely stuck on how to draw a circle in c++ any advice?

- 07-22-2003Zach L.
Need to be using a graphics library: DirectX, OpenGL, SDL, etc... There are some OpenGL tutorials on this site.

- 07-22-2003FillYourBrain
trig man, trig

you know that unit circle thing they taught you? you need it.

Sines and Cosines are a wonderful thing - 07-22-2003DougDbugStandard ANSI/ISO C++ has NO GRAPHICS!
There are NO graphics in standard C++. Your compiler may have a graphics library (graphics.h or something). If not, like Zack L. said, you need an additonal 3rd-party library.

You should not have to use trigonometry to calculate a circle. And, that won't help if you can't "draw" on the screen. For example, I believe Windows has a DrawCircle() function... although I'm not sure if that's the correct name of the function. - 07-22-2003FillYourBrain
ah, but you use trig indirectly when you use the library. I assumed that he is able in some form to draw graphics because of the nature of the post. If the method he's using does not include a circle routine he could easily write one.

Common method:

cosine table pre-calculated. You create a series of points around the circle and simply draw lines from point to point. since the cosine table is pre-generated you get to draw them with blazing speed.

Zach and Doug, your graphics library is doing the same thing I assure you.;) - 07-22-2003Zach L.
Of course you need trig, but chances are that the graphics library will contain either a draw_circle type function or a draw_ellipse with variable eccentricity, which you merely set to 0, and you're good.

By the way, here are some links:

www.opengl.org

www.libsdl.org - 07-22-2003VirtualAce
newx=x+cos(angle)*radius;

newy=y+sin(angle)*radius;

This is the general idea but you will need much more. Check out google - many many sites talk about several diff methods of doing this.