[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Re: [Tutor] Fastest (x,y) distance calculation



> [Raymond Hettinger]
>> > Distance calculations are much cheaper if you store the coordinates
>> > as complex numbers and use abs().

I don't know the concept behind using complex numbers and abs to determine
distance. How does that work?

> Executive summary:   abs(z1-z2)  beats  the (deltax**2 + deltay**2)
> approach

(deltax * deltax) + (deltay * deltay) beats the **2 approach, but only
decreases ~0.8 times when I tried it.

I'm also considering creating some sort of data structure that aids in
nearest-point calculating. Any suggestions?

--
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em