[comp.sys.mac.games] Hex distances

hp48sx@wuarchive.wustl.edu (HP48SX Archive Maintainer) (11/17/90)

I have just been doing a little symbolic math to use in calculating
distances on a hex map.

I am not sure if I completely understood the question, but if you want
the distance from the center of one hex to the center of another, and
all you know is how many hexes forward and to the side a piece is moved
then it is a very simple problem.

Say you move forward a hexes, and then turns left (this is a 60 degree
turn) and moves further b hexes. The total distance from the center of
the start hedx to the center of the end hex is :
sqrt( (a+b/2)^2 + (b*sin(60 degrees))^2 )
and a acceptable approximiation for sin(60 degrees) is 181/209.



-- 
*******************************************************
Povl H. Pedersen             hp48sx@wuarchive.wustl.edu
HP48sx archive maintainer

firth@sei.cmu.edu (Robert Firth) (11/19/90)

Distances on hexagonal tesselations.

Let the distance between the centre of a hex and the centre
of an adjacent hex be 1.  Consider the hexes to be laid out
in successive horizontal rows, so each successive row is
displaced a half unit.

Let the coordinate axes be horizontal and upward right sloping diagonal.
These coordinate axes are at an angle of pi/3, or 60 degrees.

Given two hexes whose coordinates differ by H (horizontal) and
D (diagonal), then we have:

delta_x  =  H + D cos pi/3  =  H + D/2
delta_y  =      D sin pi/3  =  D sqrt(3)/2

Hence the total distance is given by

dist  =  sqrt(delta_x^2 + delta_y^2)

which simplifies to

dist  =  sqrt(H^2 + D^2 + HD)

Hope that helps.