[SciPy-User] Bresenham algorithm?

David Warde-Farley dwf at cs.toronto.edu
Mon Sep 21 03:23:33 EDT 2009


On 21-Sep-09, at 2:42 AM, Sebastian Haase wrote:

> If you comment out the list/tuples handling - assuming you want to
> plug in numpy arrays here, you have to know the number of points up
> front.
> (To be able to pre-allocate the array correctly)
> Is this easy ?  (rounding errors ?)

Yes, notice that the loop termination condition. You'd simply need to  
allocate two arrays, each 'dx' long. But in his case, he'd be better  
off taking the image array as an argument and accessing each pixel as  
he goes in order to sum them. Assuming the image is reasonably scaled  
and he uses an appropriate precision accumulator, that seems like the  
best way to approach the problem rather than allocating space for  
indices only to use them once (a more general purpose implementation,  
of course, would have to accumulate/return indices).

David



More information about the SciPy-User mailing list