More pythonic circle?

Pythor pythor at gmail.com
Sun Apr 9 20:16:41 EDT 2006


John Machin wrote:
> [Michael Tobis]
> Also, with this code, you are using radius for the dimensions of the
> enclosing box, as well as the radius of the circle, so it's guaranteed
> to not to actually produce a whole circle. Recall what python does with
> negative indices!
>
> [Pythor]
> I'm not sure what you mean here.  It produces an eighth-circle, and
> then plots each point in the 8 symmetrical positions on the circle.
> Except for the (dx+1) point made above, what piece of the circle is
> missing?
> ======
> What Michael means is that for example a circle of radius 5 is 11
> pixels wide and 11 pixels high. You are trying to cram it into a box of
> 5 x 5 pixels [or maybe 6x6 (I'm numpy-challenged)]. The result will
> resemble a train smash. Have you considered *TESTING* your code? It's
> not very difficult at all to draw the expected results for radii of
> about 4 or 5 pixels on the back of an envelope ...
>
Sure, I tested it.  And it works, for the most part.  I did miss those
the dx+1 points, which John pointed out.  On the other hand, I'm not
having any trouble producing a whole circle, while you seem to think
I'm only producing half a circle.  The code that limits itself to a 5x5
box is only expected to produce an eighth of the circle.  The actual
assignment portion uses reflection to plot points in the whole area.
If there's some other problem with it, I haven't noticed.
> By the way, there are signs of a benchmark war breaking out. What are
> typical sizes you would be using in practice for the radius and the
> enclosing box?
>
Well, I'm not really asking someone else to write my code for me, but
here goes.

The desire is to have an array of about 1000 X 1000, bigger would be
better.  I want to fill this array with regions of values, with each
region being between .5% and 5% of the total area.  I'm using random
circular regions placed around the array, allowing new regions to
overlap old ones.  So, I'm using circles of roughly 5 to 50 radius, and
throwing a few thousand into the array.
Actually, this is a prelude to trying the same thing with spheres in a
3-dimensional array, but a 1000X1000x1000 array is larger than my
memory can handle.




More information about the Python-list mailing list