(K, L), where K and L are integers.
K and L have the same parity.
(x, y) of the point (K, L) are given by the formulas:
x = 3 K n/2
y = sqrt(3) L n/2
n is the side of the hexagons.
(x, y), to find the coordinates (K, L) of the hexagon it belongs to. We can use the function floor() (from math.h) to find the point (K, L) immediately to the bottom left of (x, y). Now, two things could happen: either (K, L) is the center of an hexagon, or it isn't, depending on its parity. In each case, we have to compare the distance from (x, y) to two different points (using the Pythagorean Theorem). The shortest distance will indicate the hexagon to which the point belongs.
(K, L) coordinates of the starting and ending hexagons, we have to find the number of hexagons the bee has to jump to get from one to the other. Each step has length sqrt(3)*n. The path always has an L shape (unless the hexagons are aligned in a straight line, in which case the path is just a straight line). There are two possibilities: either the path goes first diagonally down and then diagonally up, or first diagonally and then vertically:
abs(L2-L1) < abs(K2-K1)
abs(L2-L1) > abs(K2-K1)
abs(K2-K1)
abs(K2-K1) + (abs(L2-L1) - abs(K2-K1))/2
9 1 4 5 1
5.000.
Home page |
![]() |
© 2001-2004, Gabriel Nivasch |