Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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? –  Jakobud Nov 29 '12 at 21:49
    
@Jakobud i edited it, you may understand it better now. tell me if you do. –  user31280 Nov 29 '12 at 21:53
    
@Jakobud $(r,c)$ is (row, column) and $x=\cfrac{r+c}{2}$. –  user31280 Nov 29 '12 at 21:58
1  
(r+c)/2... geez how did I not see that? Thank you very much! –  Jakobud Nov 29 '12 at 22:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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