code: def is_within_distance(
      target_transform,
      reference_transform,
      max_distance,
      angle_interval=None,
  ):
      """
      Check if a location is both within a certain distance from a reference object.
      By using 'angle_interval', the angle between the location and reference transform
      will also be tkaen into account, being 0 a location in front and 180, one behind.
  
      :param target_transform: location of the target object
      :param reference_transform: location of the reference object
      :param max_distance: maximum allowed distance
      :param angle_interval: only locations between [min, max] angles will be considered. This isn't checked by default.
      :return: boolean
      """
      target_vector = np.array(
          [
              target_transform.location.x
              - reference_transform.location.x,
              target_transform.location.y
              - reference_transform.location.y,
          ]
      )
      norm_target = np.linalg.norm(target_vector)
  
      # If the vector is too short, we can simply stop here
      if norm_target < 0.001:
          return True
  
      # Further than the max distance
      if norm_target > max_distance:
          return False
  
      # We don't care about the angle, nothing else to check
      if not angle_interval:
          return True
  
      min_angle = angle_interval[0]
      max_angle = angle_interval[1]
  
      fwd = reference_transform.get_forward_vector()
      forward_vector = np.array([fwd.x, fwd.y])
      angle = math.degrees(
          math.acos(
              np.clip(
                  np.dot(forward_vector, target_vector) / norm_target,
                  -1.0,
                  1.0,
              )
          )
      )
  
      return min_angle < angle < max_angle
  
file_path: carla/PythonAPI/carla/agents/tools/misc.py
imports: import math
  import numpy
  import carla
label_desc: Use image node_id 4 for calling a global function with example usage: is_within_distance(target_transform, reference_transform, max_distance, angle_interval) and returns: unknown, True, False, True