How to calculate distances on a hexagonal grid

Took Help from # http://web.archive.org/web/20080223153151/http://www.drking.plus.com/hexagons/misc/grid.html

We can refer to a cell as [x,y]. We assume the distance between the centres of two adjacent cells is 1

1. ‘Cell by cell’ moves

What is the minimum distance that a (chess) king would travel if it started at cell [x0,y0] and ended at [x1,y1]? We assume the king moves one cell at a time in any direction, and that x1>=x0 (swap the cells if x1<x0)

Answer:-
IF y1>y0 THEN Distance=x1-x0+y1-y0
ELSEIF x0+y0>x1+y1 THEN Distance=y0-y1
ELSE Distance=x1-x0

The 3 cases correspond to the king moving
NorthEast then Up
SouthEast then Down
NorthEast then SouthEast or vice versa

2. ‘As the crow flies’

The distance between the centres of cells [x0,y0] and [x1,y1] is given by:-

Should you wish to calculate the distance (as the crow flies) without using a coordinate system – simply moving y cells in the y-direction then x cells in the x-direction (or vice versa), the formula simplifies to:-