Useful tools for working with hexagonal grids
30 Stars
Updated Last
1 Year Ago
Started In
December 2013


Build Status

This package provides some basic utilities for working with hexagonal grids. It is largely works from Amit Patel's terrific refererence.


Hexagonal grids can be indexed a number of different ways. Indexes are represented with one of the Hexagon types. The following are currently provided:

HexagonAxial(q, r)
HexagonCubic(x, y, z)
HexagonOffsetOddR(q, r)
HexagonOffsetEvenR(q, r)

One indexing system can be converted to another with convert.

convert(HexagonOffsetOddR, HexagonAxial(2, 4))

The six points (in cartesian space) of a hexagon can be iterated through with points.

for (x, y) in vertices(HexagonAxial(2, 3))
    # ...

The center point can be obtained with center

x, y = center(HexagonAxial(2, 3))

A point in cartesian space can be mapped to the index of the hexagon that contains it with the cube_round function.

h = cube_round(23.5, 4.67)


This library is not mature or complete, but provides just enough to implement hexagonal bin visualizations. If your hexagon project requires something that's not provided, file bug or pull request.

Required Packages

No packages found.