Hexagon grid coordinate system

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?


In the interest of closing the question I've posted this answer, but full credit for the answer goes to Michael Lugo for his comment on my initial Post.

All information comes from this link. It goes into far more detail than this answer.

There are multiple approaches to labeling Hexagon grids, each with advantages and disadvantages.

Offset coordinates

The most common approach is to offset every other column or row. Columns are named col or q. Rows are named row or r. You can either offset the odd or the even column/rows, so the horizontal and vertical hexagons each have two variants.

Offset coordinates, horizontal layout

Cube coordinates

Another way to look at hexagonal grids is to see that there are three primary axes, unlike the two we have for square grids. There’s an elegant symmetry with these.

enter image description here

Instead of having two values per coodinate, representing how far North and South the hexagon is, you can use three dimensions.

Axial Coordinates

The axial coordinate system, sometimes called “trapezoidal”, is built by taking two of the three coordinates from a cube coordinate system. Since we have a constraint such as x + y + z = 0, the third coordinate is redundant. Axial coordinates are useful for map storage and for displaying coordinates to the user. Like cube coordinates, you can use the standard add, subtract, multiply, divide operations from cartesian coordinates.

enter image description here

So for my purposes, the most useful map system was cube coordinates, as they have the simplest and most consistent rules for changing coordinates based movement between cells.


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) 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).