I am using flat topped hexagonal grid (following the manual listed here http://www.redblobgames.com/grids/hexagons/).
I need to convert my cube coordinates into pixel coordinates. I have read Hexagonal Grid Coordinates To Pixel Coordinates but the solution listed there requires some modifications to work with flat topped grid. The logic must be similar to the one described in the question linked above but I can't work it out.
Definitely in case of flat top hexes x-coordinate may be used as x pixel coordinate. Thus calculating X pixel coordinate from cube coordinates is relatively easy. Assuming that $this->hexSize
is total width of hex and $cubeCoordinate
is an array of x,y,z coordinates the x-pixel coordinate will be:
$pixelCoordinate['x'] = $this->hexSize * $cubeCoordinate['x'] * 3/4;
I can't work out though how to calculate y pixel coordinate. The height between adjacent hexes should be deficiently equal to $this->hexSize
. But how to calculate offset based on cube coordinates?