MCPcopy Create free account
hub / github.com/Rex-sys-hk/PlanScope / plot_actor_bounding_box

Function plot_actor_bounding_box

src/utils/vis.py:27–80  ·  view source on GitHub ↗

Plot an actor bounding box centered on the actor's current location. Args: ax: Axes on which actor bounding box should be plotted. cur_location: Current location of the actor (2,). heading: Current heading of the actor (in radians). color: Desired color for the b

(
    ax: plt.Axes,
    cur_location: np.ndarray,
    heading: float,
    color: str,
    bbox_size: Tuple[float, float],
    alpha=1.0,
    label=None,
    zorder=50,
    fill=True,
)

Source from the content-addressed store, hash-verified

25
26
27def plot_actor_bounding_box(
28 ax: plt.Axes,
29 cur_location: np.ndarray,
30 heading: float,
31 color: str,
32 bbox_size: Tuple[float, float],
33 alpha=1.0,
34 label=None,
35 zorder=50,
36 fill=True,
37) -> None:
38 """Plot an actor bounding box centered on the actor's current location.
39
40 Args:
41 ax: Axes on which actor bounding box should be plotted.
42 cur_location: Current location of the actor (2,).
43 heading: Current heading of the actor (in radians).
44 color: Desired color for the bounding box.
45 bbox_size: Desired size for the bounding box (length, width).
46 """
47 (bbox_length, bbox_width) = bbox_size
48
49 # Compute coordinate for pivot point of bounding box
50 d = np.hypot(bbox_length, bbox_width)
51 theta_2 = math.atan2(bbox_width, bbox_length)
52 pivot_x = cur_location[0] - (d / 2) * math.cos(heading + theta_2)
53 pivot_y = cur_location[1] - (d / 2) * math.sin(heading + theta_2)
54
55 vehicle_bounding_box = Rectangle(
56 xy=(pivot_x, pivot_y),
57 width=bbox_length,
58 height=bbox_width,
59 angle=np.degrees(heading),
60 fc=color if fill else "none",
61 ec=color,
62 alpha=alpha,
63 label=label,
64 zorder=zorder,
65 )
66 ax.add_patch(vehicle_bounding_box)
67
68 if bbox_length > 1.0:
69 direction = (
70 0.25 * bbox_size[0] * np.array([math.cos(heading), math.sin(heading)])
71 )
72 ax.arrow(
73 cur_location[0],
74 cur_location[1],
75 direction[0],
76 direction[1],
77 color="white",
78 zorder=zorder + 1,
79 head_width=0.5,
80 )
81
82
83def plot_box(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected