作者:邬杨明
1 import numpy 2 from pylab import * 3 4 # 定义一个含有障碍物的20×20的栅格地图 5 # 10表示可通行点 6 # 0表示障碍物 7 # 7表示起点 8 # 5表示终点 9 map_grid = numpy.full((20, 20), int(10), dtype=numpy.int8) 10 # print(map_grid) 11 map_grid[3, 3:8] = 0 12 map_grid[3:10, 7] = 0 13 map_grid[10, 3:8] = 0 14 map_grid[17, 13:17] = 0 15 map_grid[10:17, 13] = 0 16 map_grid[10, 13:17] = 0 17 map_grid[5, 2] = 7 18 map_grid[15, 15] = 5 19 # 画出定义的栅格地图 20 21 # plt.imshow(map_grid, cmap=plt.cm.hot, interpolation='nearest', vmin=0, vmax=10) 22 # plt.colorbar() 23 # xlim(-1, 20) # 设置x轴范围 24 # ylim(-1, 20) # 设置y轴范围 25 # my_x_ticks = numpy.arange(0, 20, 1) 26 # my_y_ticks = numpy.arange(0, 20, 1) 27 # plt.xticks(my_x_ticks) 28 # plt.yticks(my_y_ticks) 29 # plt.grid(True) 30 # plt.show() 31 32 33 class AStar(object): 34 """ 35 创建一个A*算法类 36 """ 37 38 def __init__(self): 39 """ 40 初始化 41 """ 42 self.f = 0
A*算法在栅格地图上的路径搜索(python实现)
最新推荐文章于 2024-04-19 10:57:44 发布