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)