## Wednesday, July 9, 2014

### Coordinate Systems In Hex And Square Grids

In a grid, we use coordinates to describe an object's position within said grid. What are some of the differences and parallels between hex and square grid coordinate systems?

In both hex and square grid systems, we have a mapping of a two-dimensional plane. Because of this, any space in either system can be represented by coordinates that denote that space’s location relative to two non-parallel axes on that plane. The difference is, in a square grid those axes are typically perpendicular, while in a hex grid the axes are typically at a 60° angle.

We’ll call the space where the axes cross one another the Origin, and designate it (0,0). From here, it’s easy to see in a square grid how the coordinates are assigned. The number of spaces to the left or right of the origin is the x-coordinate, while the number of spaces above or below is the Y-coordinate.

Let’s focus on the x-coordinate for a moment. It’s easy to think of the x-coordinate as describing the current space’s distance from the y-axis, but that’s really only true in a square coordinate system, or any system with the two axes being perpendicular. Another way to look at it is that the x-coordinate identifies columns of spaces which run perpendicular to the x-axis.

Similarly, the y-coordinate denotes rows of spaces perpendicular to y-axis.

The end result is that we have coordinates that identify the row (y-coordinate) and column (x-coordinate) relative to the two axes individually. If we apply this to the hex system, we end up with a similar coordinate system, except the “rows” and “columns” are hexes rather than squares, and the axes are at a non-right angle.

You may notice that the “columns” and “rows” are adjacent hexes that are opposite one another. In this case, the x rows run upper-left to lower-right, while the y rows run upper-right to lower-left. There’s a third row that runs horizontally, which would denote a hex’s position relative to a vertical (z) axis.

This axis is totally unnecessary to uniquely identify spaces, but it can be convenient for computation and describing distances, relative positioning, etc. I will likely include this axis in most of my illustrations for completeness and for reference, but remember that only two axes are necessary to describe the location of a hex in a grid on a two-dimensional plane.