Fix math domain error in arcos through clipping.
This commit is contained in:
parent
722e258902
commit
162eac376b
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue