We have a hexagonal board (see drawing) with a face length D
We have three dimensions (directions): red, blue and green
We have line numbers in three directions (specific values ​​are not critical, they can be any)

It is necessary to make a map of the dependencies of the line number in the dimension, the position of the cell in this line for each cell of the entire board.
That is, for number 1, you need to get data in three dimensions: 1:(1,0), 2:(7,0), 3:(1,0)
similarly to the example for the number 21 : 1:(3,5), 2:(6,3), 3:(10,3)
(3,5) for example means line 3, cell 5.

For red measurement, everything is quite simple:

 S = K * D + N + summ(range(1,K-1)) - 2*summ(range(1,KD)) 

Where

  • K - line number
  • D is the size of the board (smaller face)
  • N - the number of cells in the line
  • range is a function that returns a range, and if the left border is greater than the right, then it returns 0
  • S - cell number for the entire board

I can not figure out how to calculate the other two dimensions?

enter image description here

  • one
    You have a strange grid. Typically, hexes are represented as a 2-dimensional array with an offset of each odd line by 0.5 in the drawing and access to 6 neighbors instead of 8 in logic. - Kromster
  • @KromStern thanks. So much easier. - ReinRaus

1 answer 1

I used the advice of @KromStern:

You have a strange grid. Typically, hexes are represented as a 2-dimensional array with an offset of each odd line by 0.5 in the drawing and access to 6 neighbors instead of 8 in logic.

Everything turned out much easier and clearer:

 ---*-*-*--- --*-*-*-*-- -*-*-*-*-*- --*-*-*-*-- ---*-*-*--- 

The algorithm is simple:

  • create an intermediate rectangular array according to the scheme above
  • calculate formulas for three dimensions: dim1 , dim2 , dim3
  • fill the intermediate array
  • renumber the keys of the intermediate array, starting with zero

For Python, we got the following code creating a board map:

 def dim1( k, n, d ): y = k x = abs( k - d + 1) + 2 * n return [ y, x ] def dim2( k, n, d ): t = k-d+1 y = n if t>0: y+= t x = abs( 1-d )+2*kn if t>0: x-= t return [ y, x ] def dim3( k, n, d ): t1 = k - d + 1 t2 = d - k - 1 y = n if t2>0: y+=t2 x = k + n if t1>0: x+=t1 return [ y, x ] def pushToRes( y, x, d, val, res, dimens ): ind = y*4*d+x if ( not ind in res.keys() ): res[ind] = {} res[ind][ dimens ] = val res = {} d= 7 lens = list(range(d,2*d))+list(range(2*d-2,d-1,-1)) # d=3, lens = [3,4,5,4,3] for i in range( 0, 2*d-1 ): for j in range( lens[i] ): d1 = dim1( i, j ,d ) d2 = dim2( i, j ,d ) d3 = dim3( i, j ,d ) pushToRes( d1[0], d1[1], d, [i,j], res, 1 ) pushToRes( d2[0], d2[1], d, [i,j], res, 2 ) pushToRes( d3[0], d3[1], d, [i,j], res, 3 ) print( res ) print( len( res ) ) // контроль, что число ячеек соответствует действительности x = list(res.keys()) x.sort() res2 = [ res[i] for i in x ] print( res2 )