I have a particle distribution, i.e. a set of 3D array x
,y
and z
that give the positions of N particles. I divide my domain into cells and I would like to program an algorithm which gives me how many particles I have in a cell.
I am looking for something that doesn't use too much memory. If the distribution of particles were mono-dimensional a smart idea is to sort the particles with decreasing x
.
In this way we only need to save, for every cell, the particle with smaller x
within the cell. For example I know that the 7th particle is the particle with the smaller x
that belong to cell i
. Therefore, in cell i
, we have to find particles 0 to 7.
My question is: how can I extend this to 3D? Or, how can I build a chaining mesh?
This is not a trivial problem. You might want to look at R-trees and indeed Spatial databases in general.