[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] fast sqrt? and profiling
Yeah, reducing the number of distances compared is probably a bigger
improvement than accelerating a single comparison.
Still, your star example could also be sped up by using squared
distances instead of distances. Squared distances works just as well
for sorting and comparison, i.e. finding all points in a given radius,
or finding the closest point. In a lot of cases you can get away with
never using real distances at all, so never do any sqrt :)
Cases where you do need the real distance is when you want to know how
long it takes to go somewhere, or use speed or something. But you
rarely need those inside O(n2) algorithms.
Emile
> My way is simple but all the points in boxes and only look at the
> points in the 9 boxes of your area or 27 if we are talking 3d. If they
> move put them in the right box using modulus math or was that just a
> roll right a few times?? One never remembers such stuff.. :-P
>