7

Given a set $S$ of $N$ points on a sphere, and another point $P$ on the sphere, I want to find the $k$ points in $S$ that are the closest (Euclidean or great circle distance).

I'm willing to do a reasonable amount of pre-computation. The solution must be exact and efficient (faster than linear time).

D.W.
  • 167,959
  • 22
  • 232
  • 500
JohnJ
  • 173
  • 1
  • 5

3 Answers3

4

Use the space partitioning approach to nearest neighbor search.

For instance, one approach is to use a $k$-d tree on on the surface of the sphere. You can express every point on the sphere using spherical coordinates: every point on the sphere has coordinate $(1,\theta,\phi)$. Thus, we have a 2-dimensional space with coordinates $(\theta,\phi)$. Now organize your points using a $k$-d tree, where here we are in $k=2$ dimensions. There are standard algorithms for nearest neighbor search in a $k$-d tree; heuristically, the expected running time is $O(\lg N)$.

You will have to make small modifications to the data structure to reflect that the coordinates "wrap around" modulo $2\pi$, but this is not hard. The key subroutine used in nearest neighbor search in a $k$-d tree is: given a point $P$ and a "rectangular" region $R$, find the distance from $P$ to the nearest point in $R$. In your case, the region $R$ is $[\theta_\ell,\theta_u] \times [\phi_\ell, \phi_u]$, i.e., the set of points $\{(1,\theta,\phi) : \theta_\ell \le \theta \le \theta_u, \phi_\ell \le \phi \le \phi_u\}$. It is easy to compute the distance from $P$ to the closest point in $R$. This will then let you use the standard algorithm for nearest neighbor search in a $k$-d tree.

Alternatively, instead of a $k$-d tree, you could use any other binary space partitioning tree, or you could look at metric trees, though I don't have any reason to expect them to be significantly better.

D.W.
  • 167,959
  • 22
  • 232
  • 500
2

Here are links to two different software packages that address your question. It may be worth studying each to see if the methods they employ satisfy your needs:

(1) Matlab GridSphere. "A geodesic grid is an even grid over the surface of a sphere. The algorithm is optimized for a grid generated by GridSphere and won't work on an arbitrary geodesic grid."

(2) DarkSkyApp sphere-knn .js. "provides fast nearest-neighbor lookups on a sphere....well-tested and works correctly regardless of where on the earth things are located."

Joseph O'Rourke
  • 934
  • 6
  • 9
1

You can not use a 2D projection and then use a euclidian KD-tree on that projection, degrees on a spere translate differently into distances depending on where on the sphere you are located. @D.W.s answer is therefore false.

  • One method is to convert the points into 3D Euclidian points and then use a KD-tree.
  • Another is to use a 2D projection if you are only interested in a small part of the sphere, but you then have to distort the coordinates such that movements in the x and y directions are balanced.

These are both suggested in https://stackoverflow.com/a/16015768.