Calculate distance on a grid between 2 points

I need to calculate the distance on a grid between 2 points.
The movement allowed is horizontal and vertical as well diagonal to the next neighbor (so 45 degree rotations).

So Manhattan distance is not an option. Also Euclidean distance is not an option cause then it does not move correct along the grid which can result in a to low value (as in the red line).

I’m looking to get the distance as in the green line where it moves from cell to cell.

It’s preferred that the formula is fast.

enter image description here


Source: java

Leave a Reply