2

I have collection of objects. Each object represents a coordinate range (ie, a block). What I want is to find the object near another coordinate in a given direction.

Is there a way to do this without traversing the whole collection all the time?

Yuval F
  • 20,522
  • 4
  • 42
  • 67
Ikke
  • 95,379
  • 23
  • 93
  • 119
  • Dupe of http://stackoverflow.com/questions/132319/storing-objects-for-locating-by-xy-coordinates#132393. Any reason to keep this version open? – S.Lott Nov 05 '08 at 13:53
  • Please see [this question](https://stackoverflow.com/questions/132319/storing-objects-for-locating-by-xy-coordinates#132393). – Yuval F Nov 05 '08 at 12:26

2 Answers2

1

You may want to look into Binary Space Partitioning, and similar algorithms (Quadtree comes to mind, along with variations on Plane Sweet Algorithms)

Tony Arkles
  • 1,916
  • 13
  • 14
0

While inserting the objects .. sort them by the cordinates then use divide and conquer algorithm to search for your nearest possibility

Zuhaib
  • 1,420
  • 3
  • 18
  • 31