# Are there any hex tile sizes where both width and height are integers?

I'm trying to figure out the optimal width and height (in pixels) to start building hex tiles for game development. My preference is for "flat topped" hex grids, but the math is similar for both.

I am looking for an "optimal" tile size that allows both the width and the height of the tile to be a rounded pixel number, based on the fact that height = sqrt(3)/2 * width.

My math skills being virtually nonexistent, I just ran a brute force script that ran through widths from 1 to 1024 and did not come up with a single value for w where h was an integer. Is this really the case? How does anyone create pixel-perfect hex tiles if there's no even width & height size that can accommodate a perfect hex aspect ratio?

• This is not important to gameplay. It is a form of procrastination. If it very important to you, look for the closest match instead of an actual fit. Commented Oct 19, 2014 at 6:25
• You said "pixel", right? So you're talking about programming? Internally, you would work with ints to say which cell you're in (there should be online resources about hex grids), and the drawing of the lines will be done by the computer. (Think: You can't draw a circle, either.) Commented Oct 19, 2014 at 20:24
• If you're a curious type then by all means read this where it says "Proof by infinite descent". Just Ctrl + f to find it. Commented Oct 20, 2014 at 10:27
• @Zehelvion haha and NOW I know what you mean by "procrastination" - I just spend the last 2 hours shaving the irrational numbers yak, and NOT creating a hex-tile based game. Commented Oct 20, 2014 at 15:49
• That must be quite a yak, since its fleece go on and on when represented decimally and never repeat the same pattern (really) . I didn't remember that reference from Ren & Stimpy; it's good to know. :) Commented Oct 21, 2014 at 3:40

No. √3 is an irrational number, and by definition an irrational number can not be used as a ratio between two natural numbers (integers) such as pixel counts.

However, there is no rule that says you have to use ideal hexagons in your game tiles. If you approximate it closely and avoid any miscalculations that may result, which you should be able to do with integer math anyway, you can get a good-looking product while working with easy numbers behind the scenes (if you can call 100 and 173 easy to work with).

• Nice, but √3 is the irrational number sqrt(3)=1.7320508075688772 is (say) a double, and can certainly be expressed as a ratio of integers (138907099/80198051). Commented Oct 19, 2014 at 23:10
• @SeanD Any number represented as a double or a float is a rational number. I don't see where you are going with this? Commented Oct 20, 2014 at 10:30
• NaNs are doubles, but they aren't rational. The answer claims "sqrt(3) is an irrational number" which is false in the context of programming, I was trying to draw a distinction between computer numbers and the real numbers. Commented Oct 20, 2014 at 10:47
• @SeanD Good point, computers store a close rational approximation of irrational numbers. In fact, for most rational numbers, computers store a close rational approximation also. So you could have a "perfect" hexagon in terms of the limited computer precision. We can only store 2^(numOfBits) of possible numbers within memory and there is an infinite amount of rational numbers between 0 .. 1, let alone irrational numbers of which there is greater infinite amount. Commented Oct 20, 2014 at 10:48
• Thanks for locating the √ character for me; I'll incorporate it into my answer so we don't need to argue about floating point precision. Commented Oct 20, 2014 at 13:49

Just in case anyone is interested:

Lets assume sqrt(3) is rational:

1. Therefore, there must be two integral numbers a and b such that a/b = sqrt(3)
2. We assume these numbers are coprime, if they have a common factor, we divide by it producing a coprime pair, a and b
3. We know that (a/b)^2 = 3 and therefore a^2 = 3 * b^2.
4. 3 * b^2 is devisible by 3 as b^2 is integral and therefore a^2 is also devisible by 3.
5. There are not integral numbers square is devisible by 3, but they are not. so it follows that a itself is devisible by 3. Lets define k = a/3.
6. a^2 = (3k)^2 = 3 * b^2 => 9 * k^2 = 3 * b^2 = > 3 * k^2 = b^2 which means that b is also devisible by 3.
7. This contradicts the base assumption that they are coprime integers.

Credits to wikipedie for refreshing my memory.

• Show off! ;-) +1 for refreshing my memoey Commented Oct 21, 2014 at 3:28
• @PieterGeerkens :) thanks, I managed to remember half of it (from Calculus 1) but then found it was explained real well well in wiki. Commented Oct 21, 2014 at 3:30

Lots of complex answers here. If you are looking for a 'Close enough' answer, try 7x8. Not a perfect hexagon, but close enough that most people will not notice the difference.