SYNOPSYS

In 2023 I made an asset library for godot named hexgrid.
Right now I’m working on an application to help with LOS calculations for tabletop wargames.
In the process, I came up with an alternative coordinate system for hexgrid, which I’ll explain here.

DOCUMENTATION

Hexagonal Grids - from Red Blob Games
Line of sight on a hexagonal grid

PROCEDURE

Here are the metrics of a hexagonal grid with odd rows shifted right.

Let’s switch from the metric coordinate system into an asymmetrically scaled coordinate system (Q, R).
To do so, define the new units as follows:

  • for the horizontal axis, 1 Q unit corresponds to R √3 / 2
  • for the vertical axis, 1 R unit corresponds to R / 2

This allows us to take advantage of several useful properties :

  • Homogeneous Direction Vector
  • dr = 0 and dq % 2 = 0 for any center to center horizontal vector
  • dq = 0 and dr % 6 = 0 for any center to center vertical vector
  • abs(dq) = abs(dr) for any center to center diagonal vector
  • for any q % 2 = 0 vertical vector, vertices will be crossed when (r - 2) % 6 = 0 || (r + 2) % 6 = 0
  • for any q % 2 != 0 vertical vector, vertices will be crossed when (r - 1) % 6 = 0 || (r + 1) % 6 = 0
  • given any center to center vector :
    • vertices may be crosses only if dq % 3 = 0
    • using the 2 previous statements, it’s easy to identify the crossed vertices

It’s easy to qualify any point in (Q, R).
A (Q, R) point is a center if :

1
(r % 3 == 0) && ((q % 2 == 0 && r % 2 == 0) || (q % 2 != 0 && r % 2 != 0))
A (Q, R) point is a vertex if :
1
(q % 2 == 0 && ((r - 2) % 6 == 0 || (r + 2) % 6 == 0)) || (q % 2 == 1 && ((r - 1) % 6 == 0 || (r + 1) % 6 == 0))