0

I am looking for an algorithm that can do efficient search in a grid.

I have a large array which includes all the centroid points (x,y,z)

Now for a given location (xp,yp,zp) I want to find the closest centroid to that p location.

Currently I am doing a brute force search which basically for each point p I go through all points, calculate the distance to location p and by this find out which centroid that is.

I know that octree search and kd-tree might help but not too sure how to tackle it or which one would be better.

ATK
  • 1,296
  • 10
  • 26
  • Could you maybe explain what you mean by unstructured grid and what you need it for? Maybe you don't need any grids, it sounds like you could put all centroids in a kd-tree or octree and then do a nearest neighbour search (xp,yp,zp) to locate the nearest centroid? – TilmannZ Dec 13 '18 at 17:07
  • @TilmannZ it is an unstructured mesh where the Euclidean space is discretized in an irregular pattern. Hence, it requires some sort of a topology information to make any senses of the grid. But yes you are right. We can assume that I have loads of points centroids (x,y,z), and I have loads of candidate points (xp,yp,zp) where I need to locate the nearest centriod – ATK Dec 13 '18 at 17:40
  • I have changed the text to not confuse any by the unstructured grid term – ATK Dec 13 '18 at 17:42

1 Answers1

0

I would you a spatial index, such as the kd-tree or quadtree/octree (which you suggested) or maybe an R-Tree based solution.

Put all your centroids into the index. Usually you can associated any point in the index with some additional data, so if you need that, you could provide a back-treference into the grids, for example grid coordinates).

Finding the nearest point in the index should be very fast. The returned data then allows you to go back into the grid.

In a way, a quadtree/octree is in itself nothing but a discretizing grid that get finer if the point density increases. The difference to a grid is that it is hierarchical and that empty areas are not stored at all.

TilmannZ
  • 1,784
  • 11
  • 18