ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pygame-users
pygame-users
Re: [pygame] Fastest (x,y) distance calculation
by Magnus Lie Hetland other posts by this author
Sep 10 2003 10:05PM messages near this date
Re: [pygame] Fastest (x,y) distance calculation | Re: [pygame] Fastest (x,y) distance calculation
Zak Arntson <zak@[...].com> :
> 
[snip]
>  I can't think of a better algorithm for getting the nearest object
>  than this.

There are several, actually. Some are based on spatial indexing and
the like, and you might find some standard ones in computational
geometry (at least there is a very common one for finding the two
closest points in a set). The simplest thing to do is probably to
divide your are into cells (spatial hashing, more or less) and to
search them outwards for candidates. That way you can quickly prune
away lots of candidates, and won't need to do any distance
calculations on the objects that are far away. The advantages of
fiddling with the distance calculation itself will be dwarfed by the
speedup you might get by the use of a proper searching algorithm.

For a survey of lots of relevant methods, see
http://citeseer.nj.nec.com/167339.html

(I've posted some stuff about this on the list before; then it was
about spatial (hash) join, for finding possible collisions.)

-- 
Magnus Lie Hetland                "In this house we obey the laws of
http://hetland.org                 thermodynamics!"    Homer Simpson
Thread:
Zak Arntson
Rene Dudfield
Niki Spahiev
Magnus Lie Hetland
Pete Shinners
Bob Ippolito
Zak Arntson
Magnus Lie Hetland
Nicola Larosa

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved