# How to determine what hexes are in an area bounded by 3 hexes

I've been searching for hex grid algorithms for a while now, but I'm not having much luck.

I'm working on a game that will be using hex grids for the board. There seems to be sufficient resources to manage the A* path finding routines, but trying to find something as simple as determining a set of hexes within a triangle seems to be a real challenge.

An example of what I'm looking for is that I want to have a starting coordinate. I want to get a hex that is 3 hexes to the north/east away from the source hex. I want to get a hex that is 3 hexes to the south/east away from the source hex. I then want to produce a list of all hexes bounded by these 3 hexes.

It should be simple enough, but the fact that rows are staggered is completely confounding me.

Thanks

-
I have posted a library of Hex Grid Utilities (licensed under the MIT license) here: hexgridutilities.codeplex.com that may be of use. – Pieter Geerkens Apr 15 '13 at 0:57
Ask away; I will see what I can do. I prefer to retain my email for the moment. – Pieter Geerkens May 15 '13 at 22:46

## 1 Answer

Use a Canonical (Or oblique) coordinate system (with axes at 120 degrees) to identify the hexes that are in the triangle. Then convert the coordinates of those hexes (with a homogenous transformation) to Rectangular coordinates for display. The utility toolkit I linked to above could be of help in writing this code.

-
+1 Nice solution concept for the problem. – Patrick Hughes Apr 15 '13 at 1:47
I've spent a short while going through the code in your utility. Once I figure out the meaning of your canonical coordinates, I might be able to make use of the algorithms it uses. – Paul Mouchet Apr 15 '13 at 11:55
I meant to add to the comment - even though much of the code/math is over my head, the code is well written. Thanks! – Paul Mouchet Apr 15 '13 at 11:56
Okay, I've solved the question. I couldn't get much out of the source code in Pieter's toolbox, but I was able to use the concept of his answer to come up with a solution. I was going to post the source code, but the comment-size limit is preventing me. If there is a good way to provide source code here, let me know and I'll include it. – Paul Mouchet Apr 15 '13 at 16:34
@PaulMouchet: thank you for the complement. If you have specific questions about the code, that could be answered as part of expanding/improving the documentation, I would look at answering them. – Pieter Geerkens Apr 16 '13 at 2:41