Created
January 16, 2013 04:53
-
-
Save McFunkypants/4544738 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// distanceFunction functions | |
// these return how far away a point is to another | |
function ManhattanDistance(Point, Goal) | |
{ // linear movement - no diagonals - just cardinal directions (NSEW) | |
return abs(Point.x - Goal.x) + abs(Point.y - Goal.y); | |
} | |
function DiagonalDistance(Point, Goal) | |
{ // diagonal movement - assumes diag dist is 1, same as cardinals | |
return max(abs(Point.x - Goal.x), abs(Point.y - Goal.y)); | |
} | |
function EuclideanDistance(Point, Goal) | |
{ // diagonals are considered a little farther than cardinal directions | |
// diagonal movement using Euclide (AC = sqrt(AB^2 + BC^2)) | |
// where AB = x2 - x1 and BC = y2 - y1 and AC will be [x3, y3] | |
return sqrt(pow(Point.x - Goal.x, 2) + pow(Point.y - Goal.y, 2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment