Yes the threshold d can be fixed. I could build an uniform grid of cubes but I don't understand how update and remove point from the grid.
Every bin contains a set of points, and each point is in exactly one bin of your grid. This set of points can be stored in a resizable list or array; to add a point to such a list you can simply append it, to delete you need a linear search (but there should be very few points in each cell).
if the the edge cell have size d, before I find the cell where point is in and to find the closest point
There is no need to find the closest point, only any point that's closer than d
; sometimes you'll pick the closest point by chance, but it isn't significant.
with distance Insertion and deletion what's operation needs? Find the right cell and remove or insert new point?
I don't understand what you mean. Finding the right cell is trivial; you only have to divide point coordinates by d
and round consistently (e.g. floor) to obtain the index of the cell in the grid that contains the point.
What's happen if the new point inserted is out the bbox of the initial grid.
How is it inserted?
If you need to support a huge range of point positions you need an infinite grid rather than a bounded one. There are two very similar simple approaches:
- Wrapping with modular arithmetic: choose a grid height H, width W and depth D such that H*W*D (the total number of cells) is tolerable and hopefully larger than the size of a typical point set. Then, instead of directly using potentially huge and out of bounds integer grid indices i=floor(x/d), j=floor(y/d), k=floor(z/d), place point (x,y,z) in cell (i%W, j%H, k%D). This has the effect of mixing together points from "aliased" distant places, which will be occasionally tested and found useless, wasting a little time. Obviously, neighbour cell indices computed by adding and subtracting 1 might wrap around to the opposite side of the grid; this easy and robust management of boundaries could be reason enough to adopt this kind of scheme, even with a small domain.
- Arbitrary hashing: decide on a certain number N of bins, then map i,j,k to the 0...n-1 range with a hash function (which could be hard to choose correctly).
Edited by LorenzoGatti, 29 November 2012 - 11:38 AM.