Line Crossing a hexagon grid

Setting up the grid of hexagon “Centers”.
It is easiest to make the 00,00 hexagon have the X, Y location of 0,0

  1. Make 00, 00 hexagon center define the location of the X, Y plane zero point
  2. The even hexagons (column number is even) are higher than the odd hexagons in a given row

The center of any hexagon in this array can be determined by its Col, Row
Examples
the center of 00, 00 is X = 0, y = 0
the center of 01, 00 is X = 1.5, y = -h
the center of 01, 01 is X = 1.5, y = -h * 3
the center of 02, 02 is X = 3, y = -h * 4
the center of 03, 03 is X = 4.5, y = -h * 7

General Formula: the center of col, row is:
if col is even:
X = col * 1.5, Y = (-2 * row) * h
if col is odd:
X = col * 1.5, Y = ((-2 * row) - 1) * h

This makes it easy to define the centers of all the hexagons in the grid of tiled hexagons.
The red lettering is the center of the hexagon X, Y defined in the coordinate system.

Sorry, not an answer to the question, but in case you or others in the thread are unaware, red blob games has an exceptional article on working with hexagons: Hexagonal Grids. Highly recommended reading.

1 Like

Thanks Jeffrey, I know this link and read it. Another think is to understand and use it.

Thanks Robert,
I’ll try first to understand and then implement your code, I’ll let you know if it now works as expected.