Nearest neighbor search with periodic boundary conditions

前端 未结 2 1733
-上瘾入骨i
-上瘾入骨i 2021-02-05 23:08

In a cubic box I have a large collection points in R^3. I\'d like to find the k nearest neighbors for each point. Normally I\'d think to use something like a k-d tree, but in th

2条回答
  •  别那么骄傲
    2021-02-05 23:55

    (I'm posting this answer even though I'm not fully sure it works. Intuitively it seems right, but there might be an edge case I haven't considered)

    If you're working with periodic boundary conditions, then you can think of space as being cut into a series of blocks of some fixed size that are all then superimposed on top of one another. Suppose that we're in R2. Then one option would be to replicate that block nine times and arrange them into a 3x3 grid of duplicates of the block. Given this, if we find the nearest neighbor of any single node in the central square, then either

    1. The nearest neighbor is inside the central square, in which case the neighbor is a nearest neighbor, or
    2. The nearest neighbor is in a square other than the central square. In that case, if we find the point in the central square that the neighbor corresponds to, that point should be the nearest neighbor of the original test point under the periodic boundary condition.

    In other words, we just replicate the elements enough times so that the Euclidean distance between points lets us find the corresponding distance in the modulo space.

    In n dimensions, you would need to make 3n copies of all the points, which sounds like a lot, but for R3 is only a 27x increase over the original data size. This is certainly a huge increase, but if it's within acceptable limits you should be able to use this trick to harness a standard kd-tree (or other spacial tree).

    Hope this helps! (And hope this is correct!)

提交回复
热议问题