Hexagon grids: coordinate systems and distance calculations

카테고리 없음 2015. 2. 24. 16:41
반응형

http://www.redblobgames.com/grids/hexagons/


http://keekerdc.com/2011/03/hexagon-grids-coordinate-systems-and-distance-calculations/




This way, every hex will actually have three coordinates. It’s less complicated than you might think, however, when we actually look at this section of grid we’ve been working with, with the values plotted. Have a look and see if you can pick out the interesting relationship that appears between the coordinate values within each tile:

That’s right kids; the coordinates of any given tile add up to 0. x + y + z = 0 no matter what direction in which you traverse the grid or how far you go. Yes, that also means that the z-axis is technically a bit redundant in some situations, such as determining where to render each tile on the screen, however its advantage is clear when it comes to pathfinding and distance calculation. Now, we have a consistent coordinate system in all directions on the grid – a truly flat system – and so we can arrive upon this formula for determining the distance between any two tiles, which should look pretty similar to a distance formula we examined earlier, in the context of Civ games:

Just as in the example of the square grid, in which a move to any of the eight neighboring tiles counts as the same unit of movement; we arrive at a similar equation with a three-coordinate hex grid in which a move to any of the six neighboring tiles counts as the same unit of movement. This is why a hex grid is preferable to a square grid when considered from the context of constraining movement to a grid – its the more accurate means of modeling movement that reaches further than one tile since there’s three axes to move along instead of two, and you can use it without bending Pythagoras completely out of shape.

반응형
: