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.


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 }$$

  • $\begingroup$ I'm confused with that syntax and how that helps me... I'm not trying to determine if a hex exists at a row/column or not. I'm trying to determine the x,y coordinate that that hex... In your equation, what does the comma and triple equal sign mean? $\endgroup$ – Jake Wilson Nov 29 '12 at 21:49
  • $\begingroup$ @Jakobud i edited it, you may understand it better now. tell me if you do. $\endgroup$ – user31280 Nov 29 '12 at 21:53
  • $\begingroup$ @Jakobud $(r,c)$ is (row, column) and $x=\cfrac{r+c}{2}$. $\endgroup$ – user31280 Nov 29 '12 at 21:58
  • 1
    $\begingroup$ (r+c)/2... geez how did I not see that? Thank you very much! $\endgroup$ – Jake Wilson Nov 29 '12 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.