# Circle Algorithm

Archives Forums/BlitzPlus Programming/Circle Algorithm

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...?

Looks like lots of circle algorithms in the code archives...

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.

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.   