What is the fastest way to find the closest point to a given point?

后端 未结 9 2102
情歌与酒
情歌与酒 2020-11-28 07:18

What is the fastest way to find closest point to the given point in data array?

For example, suppose I have an array A of 3D points (with coordinates x,

相关标签:
9条回答
  • 2020-11-28 07:26

    check this out.. You can consult CLRS computational geometry chapter also.. http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf

    0 讨论(0)
  • 2020-11-28 07:28

    I would use a KD-tree to do this in O(log(n)) time, assuming the points are randomly distributed or you have a way to keep the tree balanced.

    http://en.wikipedia.org/wiki/Kd-tree

    KD trees are excellent for this kind of spatial query, and even allow you to retrieve the nearest k neighbors to a query point.

    0 讨论(0)
  • 2020-11-28 07:29

    You may organize your points in an Octree. Then you only need to search a small subset.

    A Octree is a fairly simple data structure you can implement yourself (which would be a valuable learning experience), or you may find some helpful libraries to get you going.

    0 讨论(0)
  • 2020-11-28 07:36

    If you're doing a once-off nearest neighbour query, then a linear search is really the best you can get. This is of course assuming the data isn't pre-structured.

    However, if you're going to be doing lots of queries there are a few space-partitioning data structures.These take some preprocessing to form the structure, but then can answer nearest neighbour queries very fast.

    Since you're dealing with 3D space, I recommend looking at either octrees or kd-trees. Kd-trees are more generic (they work for arbitrary dimensions) and can be made more efficient than octrees if you implement a suitable balancing algorithm (e.g. median works well), but octrees are easier to implement.

    ANN is a great library using these data structures, but also allowing for approximate nearest neighbor queries which are significantly faster but have a small error as they're just approximations. If you can't take any error, then set the error bound to 0.

    0 讨论(0)
  • 2020-11-28 07:36

    I suggest KD-tree will work fine. Also good for nearest neighbour searches.

    0 讨论(0)
  • 2020-11-28 07:38

    The "Fastest" way to do it, considering the search ONLY, would be to use voxels. With a 1:1 point-voxel map, the access time is constant and really fast, just shift the coordinates to center your point origin at the voxel origin(if needed) and then just round-down the position and access the voxel array with that value. For some cases, this is a good choice. As explained before me, octrees are better when a 1:1 map is hard to get( too much points, too little voxel resolution, too much free space).

    0 讨论(0)
提交回复
热议问题