[MUD-Dev] Re: Hex-grid mapping

Jon Leonard jleonard at divcom.slimy.com
Tue Dec 1 00:13:54 CET 1998


On Tue, Dec 01, 1998 at 02:42:18AM -0500, Matthew R. Sheahan wrote:
> i'm in the design phase for a project where i want to use hex-grid
> mapping, and this has led me to realize that i don't know any decent
> methodology at all for tracking coordinates on a hex-grid.  ideally
> i'd like something not very different from Cartesian coordinates, and
> which permits easy determination of what locations are adjacent to
> a given coordinate.  this seems like the kind of thing which has
> probably been solved to death, so i thought i'd ask around instead of
> reinventing the wheel.   does anyone have any suggestions, or resources
> to point me to?

Treat it just like cartesian coordinates, except that instead of using
sqrt(x*x + y*y) for distance, use sqrt(x*x - x*y + y*y).

That gives a coordinate grid that looks like this:

                      /   \   /   \   /   \   /   \   /   \   /   \   
                    |  0,5  |  1,5  |  2,5  |  3,5  |  4,5  |  5,5  |
                  /   \   /   \   /   \   /   \   /   \   /   \   /
                |  0,4  |  1,4  |  2,4  |  3,4  |  4,4  |  5,4  |
              /   \   /   \   /   \   /   \   /   \   /   \   /
            |  0,3  |  1,3  |  2,3  |  3,3  |  4,3  |  5,3  |
          /   \   /   \   /   \   /   \   /   \   /   \   /
        |  0,2  |  1,2  |  2,2  |  3,2  |  4,2  |  5,2  |
      /   \   /   \   /   \   /   \   /   \   /   \   /
    |  0,1  |  1,1  |  2,1  |  3,1  |  4,1  |  5,1  |
  /   \   /   \   /   \   /   \   /   \   /   \   /
|  0,0  |  1,0  |  2,0  |  3,0  |  4,0  |  5,0  |
  \   /   \   /   \   /   \   /   \   /   \   /

Adjacent hexes have a distance of 1, and are located at deltas of:
(-1,+0) (-1,+1) (+0,-1) (+0,+1) (+1,-1) (+1,+0)

Using +x*y instead of -x*y in the distance formula yields a hex grid
skewed the other way.

I have some code that I can clean up if an example would be helpful.

Jon Leonard




More information about the mud-dev-archive mailing list