Article URL: https://redblobgames.github.io/circular-obstacle-pathfinding/ Comments URL: https://news.ycombinator.com/item?id=48886040 Points: 10 # Comments: 1

The A* pathfinding algorithm is a powerful method for quickly generating optimal paths. Typically, people demonstrate A* navigating grid-based maps, but A* isn’t just a grid algorithm! It can work on any graph. We can use A* to find a path through this world of round obstacles. How does the same algorithm solve both problems? Let’s start with a review of how A* works. The A* algorithm finds the optimal path from the start point to the end point, avoiding obstacles along the way. It does this by gradually expanding a set of partial paths. Each partial path is a series of steps from the start point to some intermediate point on the way to the goal. As A* progresses, the partial paths get closer and closer to the goal point. The algorithm terminates once it finds a complete path that it can prove to be better than any of the remaining possibilities. At each step in the algorithm, A* evaluates the set of partial paths and generates some new paths by expanding the most promising path in the set. To do this, A* keeps the partial paths in a priority queue, sorted by estimated length—the actual measured length of the path so far, plus a guess of the remaining distance to the goal. This guess must be an underestimate; that is, the guess can be less than the actual distance, but not greater. In most pathfinding problems, a good underestimate is the geometric straight-line distance from the end of the partial path to the goal. The actual best path to the goal from the end of the partial path might be longer than this straight line distance, but it can’t be shorter. When A* begins, the priority queue contains just one partial path: the start point. The algorithm works by repeatedly removing the most promising path from the priority queue, that is, the path with the smallest estimated length. If this path ends at the goal point, the algorithm is done—the priority queue ensures that no other path could possibly be better. Otherwise, starting from the end of the partial path it removed from the queue, A* generates some new paths by taking single steps in all possible directions. It places these new paths back into the priority queue and begins the process again. A* works on a graph: a collection of nodes connected by edges. In a grid-based world, each node represents an individual grid location, while each edge represents a connection to a neighboring location to the north, south, east or west. Before A* can run on the forest of round obstacles, we need to convert it into a graph. All the paths through the forest consist of alternating line segments and arc sections . These are edges in the path graph. The endpoints of these edges become nodes . A path through the graph is a series of nodes connected by edges: Both segments and arcs act as edges in the graph. We’ll call the segments surfing edges, because the path uses them to surf between obstacles. The arcs we’ll call hugging edges, as their purpose in the path is to hug the sides of the obstacles.