I have a three dimensional array which I want to fill in with values in C#. By looping one dimension at a time it will start at one corner, and work in rows until it finishes at the opposite corner.
Standard loop:
for (int x = 0; x < 10; x++)
for (int y = 0; y < 10; y++)
for (int z = 0; z < 10; z++)
{
// fill value
}
I want to loop the same values, but start at the center of the array, and slowly work my way outward, so that if I look at the array in 3D space as it’s being filled, it will slowly grow as a ball (or cube) from the middle.
Any good ideas on how I can do this? Ideas for both filling a cube form, and filling as a sphere (ie. closest distance to middle) would be great!
You may use something like BFS
C-style pseudocode, not C#:
It will fill area by Manhettan distance. So it will cube, but corner to top and bottom
Also you may use this naive solution(pseudocode too):