Skip to content

Commit d433748

Browse files
committed
Replaced sqrt(x**2+y**2) with hypot in PathPlanning/AStar/a_star.py
1 parent 1273934 commit d433748

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

PathPlanning/AStar/a_star.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def calc_final_path(self, ngoal, closedset):
136136
@staticmethod
137137
def calc_heuristic(n1, n2):
138138
w = 1.0 # weight of heuristic
139-
d = w * math.sqrt((n1.x - n2.x) ** 2 + (n1.y - n2.y) ** 2)
139+
d = w * math.hypot(n1.x - n2.x, n1.y - n2.y)
140140
return d
141141

142142
def calc_grid_position(self, index, minp):
@@ -199,7 +199,7 @@ def calc_obstacle_map(self, ox, oy):
199199
for iy in range(self.ywidth):
200200
y = self.calc_grid_position(iy, self.miny)
201201
for iox, ioy in zip(ox, oy):
202-
d = math.sqrt((iox - x) ** 2 + (ioy - y) ** 2)
202+
d = math.hypot(iox - x, ioy - y)
203203
if d <= self.rr:
204204
self.obmap[ix][iy] = True
205205
break

0 commit comments

Comments
 (0)