Skip to content

Commit 00f8fd3

Browse files
committed
Replaced sqrt(x**2+y**2) with hypot in PathPlanning/ClosedLoopRRTStar/pure_pursuit.py
1 parent 1eb3ebb commit 00f8fd3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

PathPlanning/ClosedLoopRRTStar/pure_pursuit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ def calc_target_index(state, cx, cy):
6868
dx = [state.x - icx for icx in cx]
6969
dy = [state.y - icy for icy in cy]
7070

71-
d = [abs(math.sqrt(idx ** 2 + idy ** 2)) for (idx, idy) in zip(dx, dy)]
71+
d = np.hypot(dx, dy)
7272
mindis = min(d)
7373

74-
ind = d.index(mindis)
74+
ind = np.argmin(d)
7575

7676
L = 0.0
7777

7878
while Lf > L and (ind + 1) < len(cx):
7979
dx = cx[ind + 1] - cx[ind]
8080
dy = cy[ind + 1] - cy[ind]
81-
L += math.sqrt(dx ** 2 + dy ** 2)
81+
L += math.hypot(dx, dy)
8282
ind += 1
8383

8484
# print(mindis)
@@ -121,7 +121,7 @@ def closed_loop_prediction(cx, cy, cyaw, speed_profile, goal):
121121
# check goal
122122
dx = state.x - goal[0]
123123
dy = state.y - goal[1]
124-
if math.sqrt(dx ** 2 + dy ** 2) <= goal_dis:
124+
if math.hypot(dx, dy) <= goal_dis:
125125
find_goal = True
126126
break
127127

0 commit comments

Comments
 (0)