I have an n-Dimensional rectilinear grid, such that the edges in each dimension i are given by x_i = {x[i, 0], x[i,1], ..., x[i, Ni-1], x[i, Ni]}, with N_i edges in that dimension. I then have some density y, with shape (N0, N1, ... Ni, ... Nn-1) defined at each grid vertex. We can assume that the density varies smoothly, and the density between vertices (i.e. within a cell) can be calculated by smoothly (linearly) interpolating between vertices. How do I find the center of mass in each dimension, for each cell/bin?
Note that the answer is not just the y-weighted average of the edges of each bin. For example, consider a 2D grid with x-coordinates [0.0, 1.0], and a density [[0.0, 0.0], [1.0, 2.0]]. The y-weighted x position of vertices is 1.0, but clearly the center of mass needs to be somewhere mid-way between the edges, not up against the edge:
0.0--------2.0 -y2
| |
| * |
| |
| |
| |
0.0--------1.0 -y1
| |
x1=0.0 x2=1.0
where the * approximates the center of mass.


