No need for recursion. Just measure the distance at a 60 degree angle up or down to the point where the y coordinates match. If that point is outside of where the target is (i.e. if the target is within the 60 degree arc above or below the origin), then you're done. Otherwise add on the distance right or left from there to the point where the x coordinates match. Divide the total distance (in pixels) by the hex size (the small way, so on the order of 75-76px in your example; I'll leave it as an exercise to the reader to get a more exact number by measuring the size of a large number of hexes, and to add in appropriate rounding to make sure things work out over even larger distances than that). In Javascript-esque pseudocode: function hexDist(x1, y1, x2, y2){
assert(x1 <= x2) // assume p1 left of p2; could swap if not
vertical_distance = abs(y2 - y1) // distance up or down from p1 to p2 -- the long leg of the 30-60-90 right triangle
total_distance = vertical_distance * 2 / sqrt(3) // divide long leg by sqrt(3)/2 to get hypotenuse
x_mid = x1 + (total_distance / 2) // divide hypotenuse by 2 to get short leg: horizontal distance
if (x2 > x_mid){ // if x2 <= x_mid, then the number of hexes from p1 to p2 is the same as if p2 were at the end of the diagonal
total_distance += x2 - x_mid // if x2 > x_mid, then p2 is to the right of the diagonal, so add the extra hexes
}
return round(total_distance / 75)
}