TITLE: Hexagon grid coordinate system
QUESTION [31 upvotes]: If I had a grid of squares, they can be labeled with Cartesian coordinates such that given square $(x,y)$, you know it shares a boundary with squares $(x+1,y),(x-1,y),(x,y+1),(x,y-1)$.
Is there a way of labeling a tessellated hexagon grid, so that given any hexagon label you can work out it's neighbors?

REPLY [3 votes]: While I use  redblobgames' hexagons page for all sorts of things hexagonal, there is a simple 'other way', very similar to the cartesian neighbour calculation.
The normal way we imagine bricks (stretcher bond) has the same relationship as a hex-grid.
Recognising that bricks on every other row have a horizontal offset, we count (along the rows) using +2 increments instead of +1.
This gives us our x values as following
3:0 2 4 6 8
2: 1 3 5 7
1:0 2 4 6 8
0: 1 3 5 7
  012345678

Whereas y values are the same as cartesian.
Now we can work out our neighbours:
For any brick/hex (x, y) where (x+y)%2==1 the neighbours are (x-2,y),(x+2,y),(x-1,y+1),(x+1,y+1),(x-1,y-1),(x+1,y-1)
Placing a hex (x,y) into an approximate cartesian position can be done by (x+y%2,y) (where % is the modulo operation)
If we want to label without using +2 increments, we can still do that, but we need to use the modulo operation for calculating neighbours.
3:0 1 2 3 4
2: 1 2 3 4
1:0 1 2 3 4
0: 1 2 3 4
  0-1-2-3-4 y%2=1
  -1-2-3-4- y%2=0

Now we can work out our neighbours:
For any brick/hex (x, y) the neighbours are (x-1,y),(x+1,y),(x,y+1),(x+2(y%2)-1,y+1),(x,y-1),(x+2(y%2)-1,y-1).