Let’s say I have the following 3D discretized space, in which the indexes of the samples/nodes are sequential as it is shown in the picture.
Now consider only the horizontal middle layer.
My objective is to find a programmatically and iterative rule/s that allow me to run a spiral (like the image or similar, it can start in any direction) over the mid-layer, starting from node 254, as it is shown on the image:
As you can see in the picture, the yellow crosses show the nodes to be explored. In the first lap these nodes are consecutive while in the second they are separated by 1 node and so on.
I started to solve the problem as follows (pseudocode):
I considered size(y) = y = 13
Size(z) = z = 3
Lap 1:
- 254 – z * y = 215
- 254 – z * (y + 1) = 212
- 254 – z = 251
- 254 + z * (y - 1) = 290
- 254 + z * y = 293
- 254 + z * (y + 1) = 296
- 254 + z = 257
- 254 – z * (y – 1) = 218
- Lap 2:
- 254 – 3 * z * y = 137
- 254 – 3 * z * (y + 2/3) = 131
- …
But I think there may be a simpler, more general rule.