Three-dimensional route planning based on A* algorithm under C++

A* algorithm flow C++ implementation based on three-dimensional grid space_grid map a* algorithm c++_chase. Blog-CSDN Blog

1. Introduction to A* algorithm

The principle of the A* algorithm is this. First, imagine that you have a blank map, and then set several rectangular obstacles on the map. The map can use (x, y, z) to represent each grid, such as 10* The 10*10 three-dimensional space is divided into 10*10*10=1000 small cubes. Each cube represents a grid. The center of the cube is (x, y, z). If the obstacle is within this grid, then the Raster is 1, blank is 0.

What you need to do is to set a starting point p1 and an end point p2, and find the shortest route from the starting point to the end point. The route must be able to bypass obstacles.

Specific processing ideas:

1) Starting from the starting point, use the starting point as the current grid, obtain the adjacent grids around the current point, and then calculate the cost f of each surrounding grid, f = g + h, g represents the Euclidean distance from the grid to the starting point, h represents the estimated distance from the raster to the end point, which is generally calculated using Euclidean distance.

2) Select a raster with the smallest cost f from the surrounding rasters as the new current raster. Point the parent grid of this new current grid to the previous grid (this is to record a complete path based on the parent grid when reaching the end point), and then repeat 1).

3) Until the current grid reaches the end point, the parent node of the current grid is output to the path.

2. Code

3. Results

Guess you like

Origin blog.csdn.net/ljjjjjjjjjjj/article/details/133360563