From 162eac376bcb2ae740c44e3b53a858ec2693f9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Wed, 9 Oct 2019 12:11:14 +0200 Subject: [PATCH] Fix math domain error in arcos through clipping. --- PythonAPI/carla/agents/tools/misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PythonAPI/carla/agents/tools/misc.py b/PythonAPI/carla/agents/tools/misc.py index 1e1b4f656..e9f985535 100644 --- a/PythonAPI/carla/agents/tools/misc.py +++ b/PythonAPI/carla/agents/tools/misc.py @@ -64,7 +64,7 @@ def is_within_distance_ahead(target_transform, current_transform, max_distance): fwd = current_transform.get_forward_vector() forward_vector = np.array([fwd.x, fwd.y]) - d_angle = math.degrees(math.acos(np.dot(forward_vector, target_vector) / norm_target)) + d_angle = math.degrees(math.acos(np.clip(np.dot(forward_vector, target_vector) / norm_target, -1., 1.))) return d_angle < 90.0 @@ -82,7 +82,7 @@ def compute_magnitude_angle(target_location, current_location, orientation): norm_target = np.linalg.norm(target_vector) forward_vector = np.array([math.cos(math.radians(orientation)), math.sin(math.radians(orientation))]) - d_angle = math.degrees(math.acos(np.dot(forward_vector, target_vector) / norm_target)) + d_angle = math.degrees(math.acos(np.clip(np.dot(forward_vector, target_vector) / norm_target, -1., 1.))) return (norm_target, d_angle)