Sign in to follow this  
Ructions

drawing a circle

Recommended Posts

Ructions    116
i am trying to draw a circle on the screen. when i first click the mouse that is the center of the circle and when i click the mouse again that is the size of the circle. i dont want to use any functions. cant realy figure out all the maths stuff. if anyone has working code. or any help would be greatful thanks in advance ructions

Share this post


Link to post
Share on other sites
Stephen R    721
If you can figure all the circle drawing maths out then what are you asking? How to register the click? How to actually draw to a window? And what language are you using?

EDIT: Sorry, read cant as can. I really need to pay attention.

Share this post


Link to post
Share on other sites
smr    2468
To draw a circle:Bresenham's circle drawing algorithm

To draw a circle in the way you are talking about here, you would have to find the distance between the two points that were clicked, then draw a circle with said radius. Use the distance equation ("distance = sqrt(x2 - x1)^2 + (y2 - y1)^2)") to calculate the distance between the two clicks.

I wouldn't worry about writing my own circle-drawing algorithm. Just use those that are provided with the API.

Share this post


Link to post
Share on other sites
neon_prannock    152
I use this code to draw a circle:

*******
0>a
Repeat
DrawPoint(x*cos(a),x*sin(a))
a+(PI/72)>a
until a=2(PI)
*******

You have to adapt the code to the language your using!

Before you put this code you have to set the cursor to the center of the circle. This code wil draw many points until the circle is formed. The "x" is how big is the circle. If you want to draw more or less points of the circle just change the "72", (+72>+points)(-72>-points).

I hope this code helps! ;-)

Share this post


Link to post
Share on other sites
smr    2468
Quote:
Original post by neon_prannock
I use this code to draw a circle:

*******
0>a
Repeat
DrawPoint(x*cos(a),x*sin(a))
a+(PI/72)>a
until a=2(PI)
*******

You have to adapt the code to the language your using!

Before you put this code you have to set the cursor to the center of the circle. This code wil draw many points until the circle is formed. The "x" is how big is the circle. If you want to draw more or less points of the circle just change the "72", (+72>+points)(-72>-points).

I hope this code helps! ;-)


One problem with this method is that it is not based on pixels but angles. When drawing large circles you will end up with more of a dot-to-dot representation of a circle instead of an actual solid circle. You could solve this by drawing lines from one point to the next instead of just drawing dots. Another problem is that you will be doing far more calculations than necessary on small circles because you may very well end up filling in the same pixel more than once with this algorithm and because circles have symetry that can be exploited to reduce the number of multiplications to be done. You may also find that the edge of your circle is somewhat "dirty" because of loss of precision and rounding errors when convertinging a floating point result of your trig expressions to integers for use on the screen.

Share this post


Link to post
Share on other sites
neon_prannock    152
That's the only code I know to draw a circle without using a function. I prefer it because it is easier to understand, but I know it doesn't have many possibilities. And throught this code you can create an more complex code, depending on the case you want to use the circle.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this