Algorithm to find for all points in set A the nearest neighbor in set B

后端 未结 3 461
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 00:12

Suppose we have two sets of points A, B, and we want to find for every point in set A its nearest neighbor in set B.

There are many good algorithms to find the near

相关标签:
3条回答
  • 2020-12-15 00:32

    You may benefit from reading bentleys "writing efficient programs" where he deals with a case study of the traveling salesman program. One of the savings that he recognized was that the distince between two points involved taking a square root which was expensive. Taking the square root gives you the actual distance, not taking the square root gives you a number which can be used to compare against other relative values.

    I highly recommend reading the book. It will put your brain in the right place.

    0 讨论(0)
  • 2020-12-15 00:35
    1. Find Voronoi diagram for points of set B.
    2. Apply a Sweep line algorithm over points of set A and Voronoi diagram of set B. Wherever sweep line covers some point from set A, look between which edges of Voronoi diagram this point is located. This allows to determine to which face of Voronoi diagram this point belongs. Which gives the closest point from set B.

    Details for step 2: Keep all edges of Voronoi diagram, currently intersected by sweep line, in some ordered container. When sweep line covers some vertex of Voronoi diagram, remove/add edges, incident to this vertex, from/to container. To look, between which edges some point is located, get successor/predecessor edges to this point in container.

    Time complexity is O((M+N) log M). N = |A|, M = |B|.

    0 讨论(0)
  • 2020-12-15 00:43

    A brute force solution could be to use a dendogram of closest points of set B. Then compare each point of set A to the dendogram. You can also create the dendogram with a delaunay triangulation.

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