Esempio n. 1
0
        altitude, safe_distance = 5, 3
        self.grid = create_grid(data, altitude, safe_distance)

    def get_grid(self):
        return self.grid

    def show(self, x_values, y_values):
        skeleton = medial_axis(invert(self.grid))
        plt.imshow(self.grid, origin='lower')
        plt.imshow(skeleton, cmap='Greys', origin='lower', alpha=0.7)
        plt.xlabel('EAST')
        plt.ylabel('NORTH')

        plt.plot(x_values, y_values, 'g')
        plt.show()


start_ne = (25, 100)
goal_ne = (750., 370.)

medial = Medial('colliders.csv')
grid = medial.get_grid()

astar = Astar(grid)
found, paths = astar.travel(start_ne, goal_ne)

path = astar.trace_back(paths) if found else exit("Couldn't find a path")
xpoints, ypoints = astar.axis_points(path)

medial.show(xpoints, ypoints)
    plt.scatter(n1[1] - emin, n1[0] - nmin, c='blue')

# draw connected nodes
for n1 in g.nodes:
    plt.scatter(n1[1] - emin, n1[0] - nmin, c='red')

plt.xlabel('NORTH')
plt.ylabel('EAST')

start = list(g.nodes)[0]
k = np.random.randint(len(g.nodes))
print(k, len(g.nodes))
goal = list(g.nodes)[k]

print('start = ', start, ' goal = ', goal)

astar = Astar(g)
found, paths = astar.travel(start, goal)

if found is False: exit("Unable to find path")

path = astar.trace_back(paths)

print(path)

path_pairs = zip(path[:-1], path[1:])
for (n1, n2) in path_pairs:
    plt.plot([n1[1] - emin, n2[1] - emin], [n1[0] - nmin, n2[0] - nmin],
             'green')

plt.show()