MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / compute_magnitude_angle

Function compute_magnitude_angle

agents/tools/misc.py:98–113  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

96
97
98def 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
116def distance_vehicle(waypoint, vehicle_transform):

Callers

nothing calls this directly

Calls 1

dotMethod · 0.80

Tested by

no test coverage detected