Algorithm for moving three-dimensional coordinates without re-viewing

Let's say we have a set of three-dimensional (integer) coordinates from (0,0,0) to (100,100,100) We want to visit every possible coordinate (100 ^ 3 possible coordinates to visit) without visiting each coordinate more than once.

The sum of the differences between each coordinate in adjacent steps cannot be greater than 2 (I don’t know if this is possible, if not, then minimized), for example, the step from (0,2,1) to (2,0,0) has the total difference is 5, since | x1-x2 | + | y1-y2 | + | z1-z2 | = 5

How do we create such a sequence of coordinates?

for example, to start: (0,0,0) (0,0,1) (0,1,0) (1,0,0) (1,0,1) (0,0,2) (0, 1.1) (0.2.0) (1.1.0) (2.0.0) (3.0.0) (2.0.1) (1.0.2) (0.0 , 3) etc ...

Does anyone know an algorithm that will generate such a sequence for an arbitrary coordinate (x, y, z), where x = y = z, or can it prove that it is impossible for such an algorithm to exist? Thanks

Extra credit: show how to generate such a sequence with x! = Y! = Z: D

+3
source share
3 answers

One of the tricks (there are other approaches) is to make one row [segment] at a time, one plane [square] at a time . Turning to the last part of the question, this approach works even if the size of the visited volume is not the same in each dimension (for example: a block of size 100 x 6 x 33).

In other words:

Start at (0,0,0), 
move only on the Z axis till the end of the segment, i.e.
(0,0,1), (0,0,2), (0,0,3), ... (0,0,100), 
Then move to the next line, i.e.
(0,1,100)
and come backward on the line, i.e.
(0,1,99), (0,1,98), (0,1,97), ... (0,1,0), 
Next to the next line, going "forward"

And repeat till the whole "panel is painted", i.e ending at
... (0,100,99), (0,100,100),
Then move, finally, by 1, on the X axis, i.e.
(1,100,100)
 and repeat on the other panel,but on this panel going "upward"
etc. 

, , . , "" 101 x 101 x 101, (.. ).

! , , - "back-and-forth", , , ).

: ( , ):
! , , [] , , . , , .. , ( ), "" , "" " ..

(0,0,0) (0,0,1)
(0,1,0)                  first diagonal, only 1 in lengh.
(0,2,0)                  "turn around"
(0,1,1) (0,0,2)          second diagonal: 2 in length
(0,0,3)                  "turn around"
(0,1,2) (0,2,1) (0,3,0)  third diagonal: 3 in length
(0,4,0)                  turn around
etc.

, , "", , , , , , , , , "" , .
(, , ) "" . , ( ) , , "" 2.

+4

, , , , .

0

, , ! 1 2.
, 10 + , , , . , , , :

s = No. of steps from the prev corrdinates
c1 = Condition 1 (x = y = z)
c2 = Condition 2 (x!= y!= z)
(x,y,z) s c1 c2
---------------
(0,0,0)   *    (start)
(0,0,1) 1 
(0,1,0) 2
(1,0,0) 2
(1,0,1) 1
(1,1,0) 2
(1,1,1) 1 *
(2,1,1) 1
(2,0,1) 1    *
(2,0,0) 1
(2,1,0) 1    *
(2,2,0) 1
(2,2,1) 1
(2,2,2) 1 *
(2,3,2) 1 
(2,3,3) 1 
(3,3,3) 1 *
(3,3,1) 2 
(3,2,1) 1    *
(3,2,0) 1    *
  .
  .
  .
0

Source: https://habr.com/ru/post/1723577/


All Articles