Fix math domain error in arcos through clipping.

This commit is contained in:
Ferdinand Mütsch 2019-10-09 12:11:14 +02:00 committed by Marc Garcia Puig
parent 722e258902
commit 162eac376b
1 changed files with 2 additions and 2 deletions

View File

@ -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)