3
$\begingroup$

I have the following example image of my hexagon "grid":

enter image description here

Each Hexagon has a column and row. The coordinate system I am choosing for my hex layout is an X,Y coordinate system, with the X coordinates landing across the red lines and the Y coordinates simply equal to the row. In my image I have the X,Y coordinate for each hex displayed in the middle in the middle of the hex.

My Question: Given the row and column of a hex, how do you calculate the X,Y coordinate of the hex (or more simply, how do you calculate the X coordinate, since the Y coord = row number)?

I have tried to come up with various equations that work for each hex but no luck yet. An equation that comes close is:

x = Math.floor(column/2) + (row%2) 

But that doesn't satisfy all the hex's. I think I am on the right track.

Also, please assume that the hex grid continues infinitely down and to the right.

1 Answers 1

1

Observe that if the sum of the row and column (i'm using matrix (row, column) = $(r,c)$ notation) is even, there is a hexagon but if it is odd, there is a common side of two adjacent hexagon.

The new coordinates of the hexagon at $(r,c)$ is $(x,y)=\left(\cfrac {r+c}{2}\ ,\ r\right) \ \ \ if \ \ \ \ \ r+c \ \ \ \text{ is even }$

  • 1
    `(r+c)/2`... geez how did I not see that? Thank you very much!2012-11-29