I'm trying to create a 3D grid of Node types (a custom data-type).
To create a 2D grid, I usually use this formula:
where i is the current iteration in 1D loop, and gridsize is size of one axis of grid
x = i % gridsize,
y = floor(i / gridsize)
For example, in Python:
from math import floor
grid = list()
gridsize = 3 # 3x3 grid
for i in range(gridsize**2):
x = i % gridsize
y = floor(i / gridsize)
grid.append( Node(x, y) )
How can I alter this formula to find x, y, and z coordinates for a 3D grid, and is there a general rule for finding coordinates for nD grids?