From 00f8fd37d367aa6409b70e945356f1aa5abc4fde Mon Sep 17 00:00:00 2001 From: Guillaume Jacquenot Date: Sat, 7 Dec 2019 22:24:27 +0100 Subject: [PATCH] Replaced sqrt(x**2+y**2) with hypot in PathPlanning/ClosedLoopRRTStar/pure_pursuit.py --- PathPlanning/ClosedLoopRRTStar/pure_pursuit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py b/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py index 04907279..32faa51c 100644 --- a/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py +++ b/PathPlanning/ClosedLoopRRTStar/pure_pursuit.py @@ -68,17 +68,17 @@ def calc_target_index(state, cx, cy): dx = [state.x - icx for icx in cx] dy = [state.y - icy for icy in cy] - d = [abs(math.sqrt(idx ** 2 + idy ** 2)) for (idx, idy) in zip(dx, dy)] + d = np.hypot(dx, dy) mindis = min(d) - ind = d.index(mindis) + ind = np.argmin(d) L = 0.0 while Lf > L and (ind + 1) < len(cx): dx = cx[ind + 1] - cx[ind] dy = cy[ind + 1] - cy[ind] - L += math.sqrt(dx ** 2 + dy ** 2) + L += math.hypot(dx, dy) ind += 1 # print(mindis) @@ -121,7 +121,7 @@ def closed_loop_prediction(cx, cy, cyaw, speed_profile, goal): # check goal dx = state.x - goal[0] dy = state.y - goal[1] - if math.sqrt(dx ** 2 + dy ** 2) <= goal_dis: + if math.hypot(dx, dy) <= goal_dis: find_goal = True break