Advertisement

A* Heuristic and Cost functions

Started by November 18, 2005 08:58 PM
0 comments, last by Sneftel 19 years ago
I have a graph of connected cells where each cell has a world-space 3d-position (x,y,z), This is not a 2d-grid so I don't have an (x,y) index for a cell. A* calls two functions: Heuristic() - returns the estimated heuristic from the current cell to the goal cell. Cost() - returns the cost to travel from the current cell to a neighbor. Can I use the Euclidean distance in both the Heuristic() and Cost() functions?

float Heuristic(Cell* current, Cell* goal)
{
 return ( goal->Pos() - current->Pos() ).length();
}

float Cost(Cell* current, Cell* next)
{
 return ( next->Pos() - current->Pos() ).length();
}

Both h() and g() are in the same "space" (or scale or whatever you want to call it) so I'm thinking that should be fine... right?
Sure.

This topic is closed to new replies.

Advertisement