Explicit formulation of an bijective function that maps $\mathbb{Z}^3$ to $\mathbb{N}_0$ from the point $(0,0,0)$ outwards and it's inverse

24 Views Asked by At

I am looking for such a function, that in effect maps the point (0,0,0) to 0 and then the points "surrounding" 0, so (1,0,0),(0,1,1),(0,-1,1)... to 1,2,3,4... in ascending order. It is not important in which order the surrounding points are "visited", just that all of them are before the next more "distant" layer around the origin. meaning 0 is mapped to (0,0,0), [1,26] is mapped to all coordinates only containing 1's 0's and -1's, and so on.

What I have tried of course is finding an iterative formulation to iterate over the sides of a cube of the given sidelength, but the reverse is far more difficult and inefficient, and thus I am looking for an elegant mathematical formulation of the problem. Iterating first over an edge, and then, line by line traveling along the orthogonal to this first edge until we reach it again, then adding the iteration of a cube.

What makes it more difficult: I do not have an upper bound to the coordinates in question.

Do you have any idea how such a formulation could look like, effectively enumerating the outline of a cube explicitly, and turning a coordinate into an enumeration step?