views:

34

answers:

2

I'm writing a game in which the player may manipulate a great many objects at one time. I would like the player to be able to select objects according to the distances between them.

Given the locations of all objects, a starting object, and a distance threshold, what is the fastest way to find the subset containing the starting object for which the distance between any two objects does not exceed the threshold? Heuristic solutions are perfectly acceptable.

A: 

Depends on your data structure. Primarily, are your objects already sorted / partitioned by distance? I can't think of any distance heuristic... but you could certainly do this in parallel which should help.

matt-dot-net
Objects are currently partitioned by location, for rendering, but the particular solution is not optimal because I know it's not final, so I'm looking for structures that might offer a good trade-off between space and distance. Perhaps a quadtree?
Jon Purdy
+1  A: 

This library seems to do the trick:

"ANN is a library written in the C++ programming language to support both exact and approximate nearest neighbor searching in spaces of various dimensions.

[...]

In the nearest neighbor problem a set P of data points in d-dimensional space is given. These points are preprocessed into a data structure, so that given any query point q, the nearest (or generally k nearest) points of P to q can be reported efficiently."

Alejandro
This might work, especially since it's licensed under the LGPL. I'm concerned that it won't be able to operate in real-time for a large number of points, but I'll test it first.
Jon Purdy