Finding near neighbors

前端 未结 3 552
梦如初夏
梦如初夏 2021-02-07 07:12

I need to find \"near\" neighbors among a set of points.

\"pointSet\"

There are 10 points in the above imag

3条回答
  •  遇见更好的自我
    2021-02-07 07:43

    Another possibility, simpler than creating triangulations or voronoi diagrams, is using a neighborhood matrix.

    First place all your points into a 2D square matrix. Then you can run a full or partial spatial sort, so points will became ordered inside the matrix.

    Points with small Y could move to the top rows of the matrix, and likewise, points with large Y would go to the bottom rows. The same will happen with points with small X coordinates, that should move to the columns on the left. And symmetrically, points with large X value will go to the right columns.

    After you did the spatial sort (there are many ways to achieve this, both by serial or parallel algorithms) you can lookup the nearest points of a given point P by just visiting the adjacent cells where point P is actually stored in the neighborhood matrix.

    You can read more details for this idea in the following paper (you will find PDF copies of it online): Supermassive Crowd Simulation on GPU based on Emergent Behavior.

    The sorting step gives you interesting choices. You can use just the even-odd transposition sort described in the paper, which is very simple to implement (even in CUDA). If you run just one pass of this, it will give you a partial sort, which can be already useful if your matrix is near-sorted. That is, if your points move slowly, it will save you a lot of computation.

    If you need a full sort, you can run such even-odd transposition pass several times (as described in the following Wikipedia page):

    http://en.wikipedia.org/wiki/Odd%E2%80%93even_sort

提交回复
热议问题