Wednesday, July 16, 2014

Representing Vertices And Centers Of A Hex Grid

There are a number of applications where we want to use a hex grid system, but we want to be able to access the vertices and centers of the individual hexes. How do we represent this information programmatically?

You can represent the vertices and centers of a hex grid with a secondary hex grid. To start, we'll take a single hex.

Now, we draw lines from each vertex to the other vertices it's not already connected to, minus those it's directly opposite from. This could also be thought of as drawing rectangles using opposing sides of the hex.

Now, the space defined within these overlapping rectangles is another, smaller hex. If we eliminate the extraneous parts of these lines to focus on just this area, we end up with a perfectly centered hex within the larger hex.

If we look at the immediate surrounding hexes for the larger (major) hex, we see that the smaller (minor) hexes form a secondary grid pattern, albeit with spaces missing.

If we take the minor hex, copy it, and place those copies so that they are centered on the vertices of the major hex grid, we can complete the minor grid.

Thus, we are able to logically represent each vertex of the major hex grid, as well as the centers of the major hexes, with a minor hex grid whose axes are rotated 30+60x degrees around the center point, provided both grids share that center point.

No comments:

Post a Comment