# Calculating distance in a hexagonal grid map

Say I have this map:

The first two digits on each hex represent the X axis, the last two digits the Y axis, with 60º between both.

How do I calculate the shortest distance between two hexes? E.g. the distance between (01,01) and (07,02) is 6. The distance between (02,08) and (04,04) is 5.

Preferably without a conditional algorithm, of which I've seen a couple... All the coordinates being positive will hopefully make it simpler.

-

## migrated from rpg.stackexchange.comJul 15 '12 at 21:04

This question came from our site for gamemasters and players of tabletop, paper-and-pencil role-playing games.

Why not just count how many hexes you have to move to get from point 1 to point 2 on a shortest path? Yes, it will pad the distance in certain cases (01,01 to 07,02 becomes 7 rather than 6), but it's simple. –  Oblivious Sage Jul 15 '12 at 16:46
This definitely needs to be migrated. The answers require non-RPG math or programming expertise, hence it belongs where such experts are found, not here. –  SevenSidedDie Jul 15 '12 at 17:53
Can you explain what you mean by a "conditional algorithm" that you don't want? An explicit formula will probably need a few cases, but can be done without a full-fledged graph search. –  Rahul Jul 15 '12 at 21:12
By conditional I mean that I've seen a couple algorythms meant for programming languages; e.g. "if (x>y) then foo; else bar;". If at all possible, I'd like to have a direct formula to calculate the distance. –  willf Jul 16 '12 at 8:00