Public Group

# drawing a circle

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

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
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)
*******

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 on other sites
Quote:
 Original post by neon_prannockI use this code to draw a circle:*******0>aRepeatDrawPoint(x*cos(a),x*sin(a))a+(PI/72)>auntil 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 on other sites
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.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633703
• Total Posts
3013453
×