Calculating circle´s points coordinates.
Andrew Henshaw
andrew_dot_henshaw_at_earthling_dot_net
Thu Nov 9 22:55:08 EST 2000
"Joshua Muskovitz" <josh at open.com> wrote in message
news:3a0b07f3_3 at corp.newsfeeds.com...
> If you are working in degrees, create a list of angles with "range(0,360)"
> or something like that. Then, you can use map to substitute the
> corresponding x,y coordinates for the angle.
>
...snip...
I'm not sure of the original poster's requirements, but if he wants to plot
a set of points on a integer-based grid (e.g., a memory-mapped display),
then the Bresenham Circle algorithm is usually recommended. It's very fast
and it doesn't have a problem with "holes" in the point set.
Here's a pythonized implementation.
##########################
#
# Bresenham Circle Algorithm
#
##########################
def circle(radius):
x = 0
y = radius
switch = 3 - (2 * radius)
points = []
while x <= y:
points.extend([(x,y),(x,-y),(-x,y),(-x,-y),\
(y,x),(y,-x),(-y,x),(-y,-x)])
if switch < 0:
switch = switch + (4 * x) + 6
else:
switch = switch + (4 * (x - y)) + 10
y = y - 1
x = x + 1
return points
Good luck!
Andy Henshaw
More information about the Python-list
mailing list