Compute relative angle and distance between a target_location and a current_location :param target_location: location of the target object :param current_location: location of the reference object :param orientation: orientation of the reference object :return:
(target_location, current_location, orientation)
| 96 | |
| 97 | |
| 98 | def compute_magnitude_angle(target_location, current_location, orientation): |
| 99 | """ |
| 100 | Compute relative angle and distance between a target_location and a current_location |
| 101 | |
| 102 | :param target_location: location of the target object |
| 103 | :param current_location: location of the reference object |
| 104 | :param orientation: orientation of the reference object |
| 105 | :return: a tuple composed by the distance to the object and the angle between both objects |
| 106 | """ |
| 107 | target_vector = np.array([target_location.x - current_location.x, target_location.y - current_location.y]) |
| 108 | norm_target = np.linalg.norm(target_vector) |
| 109 | |
| 110 | forward_vector = np.array([math.cos(math.radians(orientation)), math.sin(math.radians(orientation))]) |
| 111 | d_angle = math.degrees(math.acos(np.clip(np.dot(forward_vector, target_vector) / norm_target, -1., 1.))) |
| 112 | |
| 113 | return (norm_target, d_angle) |
| 114 | |
| 115 | |
| 116 | def distance_vehicle(waypoint, vehicle_transform): |