Circle Algorithm

BlitzPlus Forums/BlitzPlus Programming/Circle Algorithm

thalamus(Posted 2005) [#1]
I need a decent circle-draw algorithm for an editor I'm writing, as I'm having trouble getting satisfactory results.

All I need is the ability to draw a circle (starting with the top-left point, as opposed to the centre point) and then plot this to an array.

Can anyone spare me hours of headscratching...?


WolRon(Posted 2005) [#2]
Looks like lots of circle algorithms in the code archives...


Grey Alien(Posted 2005) [#3]
Also if the algos start from the centre, you can just subtrack the radius from the x and y coords and you have the top left coord.


aab(Posted 2005) [#4]
A fast circle algorithm with limited precision would be to just draw a line from x+a,y+b to x+u,y+v for N loops where x,y is the centre of the circle (Keeping in mind what Grey Alien said), and a=radius*cos(A), b=radius*sin(A), u=radius*cos(A+ 360°/N), v=radius*sin(A+ 360°/N), where A increases by 360°/N each loop.
The limitation is obviously that it is not a circle but a polygon, but depending on the radius you should be able to calculate the minimum value for N such that it would appear as such.
As for drawing a line by plotting directly into an array, you could take the vector of say, point x1,y1 to point x2,y2 to be vector v1,v2, then normalise it ie magnitude 1, and then store a coordinate as floats, draw a pixel there, and then increase the coordinate by unit/normalised vector of(v1,v2) and then draw a pixel at the integer of there, and so on until as many pixels as the length of the initial v1,v2 have been plotted.