Problem Statement
Need to split an N-Dimensional MeshGrid into "cubes":
Ex) 2-D Case:
(-1,1) |(0,1) |(1,1)
(-1,0) |(0,0) |(1,0)
(-1,-1)|(0,-1)|(1,-1)
There will be 4 cells, each with 2^D points:
I want to be able to process the mesh, placing the coordinate points of each cell into a container to do further processing.
Cells = [{(-1,1) (0,1)(-1,0),(0,0)},
{(0,1),(1,1),(0,0),(1,0)},
{(-1,0),(0,0)(-1,-1),(0,-1)}
{(0,0),(1,0)(0,-1),(1,-1)}]
I use the following to generate the mesh for an arbitrary dimension d:
grid = [np.linspace(-1.0 , 1.0, num = K+1) for i in range(d)]
res_to_unpack = np.meshgrid(*grid,indexing = 'ij')
Which has output:
[array([[-1., -1., -1.],
[ 0., 0., 0.],
[ 1., 1., 1.]]), array([[-1., 0., 1.],
[-1., 0., 1.],
[-1., 0., 1.]])]
So I want to be able to generate the above cells container for a given D dimensional mesh grid. Split on a given K that is a power of 2.
I need this container so for each cell, I need to reference all 2^D points associated and calculate the distance from an origin.
Edit For Clarification
K should partition the grid into K ** D number of cells, with (K+1) ** D points. Each Cell should have 2 ** D number of points. Each "cell" will have volume (2/K)^D.
So for K = 4, D = 2
Cells = [ {(-1,1),(-0.5,1),(-1,0.5),(-0.5,0.5)},
{(-0.5,1),(-0.5,0.5)(0.0,1.0),(0,0.5)},
...
{(0.0,-0.5),(0.5,-0.5),(0.0,-1.0),(0.5,-1.0)},
{(0.5,-1.0),(0.5,-1.0),(1.0,-0.5),(1.0,-1.0)}]
This is output for TopLeft, TopLeft + Right Over, Bottom Left, Bottom Left + Over Left. There will we 16 cells in this set, each with four coordinates each. For increasing K, say K = 8. There will be 64 cells, each with four points.