block by nitaku 6173659

Hex coordinates

Full Screen

Forked from Mike Bostock’s example.

For each hex, its hexagonal coordinates are drawn.

This kind of coordinate system makes it possible to interpret the position vectors of the six hexes around the origin as direction vectors. Therefore, it is possible to sum one of them to the position vector of an hex to “move” to an adjacent one. These are the values for the six directions:

E   (+1,-1,0)
SE  (+1,0,-1)
SW  (0,+1,-1)
W   (-1,+1,0)
NW  (-1,0,+1)
NE  (0,-1,+1)

Possible use cases are: computing the shortest path on a connectivity graph based on the hexagonal tiling (Stojmenovic 2007), walking on the hexagonal cells by following a space-filling curve.

Two example hexagons are also highlighted, to show the possibility of addressing an hexagon by using its coordinates.

index.js

index.html

index.coffee

index.css

index.sass