Visualization
visualization
Visualization: SE3 trajectories and invariant plots.
Functions
plot_invariants
Plot linear and angular invariant time series.
Source code in src/dhb_xr/visualization/plot.py
plot_se3_trajectory
plot_se3_trajectory(
positions,
quaternions=None,
ax=None,
title="SE(3) trajectory",
show_orientation=False,
vis_type="arrow",
box_size=(0.03, 0.03, 0.03),
color="b",
alpha=0.7,
num_frames=8,
label=None,
)
Plot 3D position trajectory with optional orientation visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
(N, 3) position array |
required |
quaternions
|
Optional[ndarray]
|
(N, 4) quaternion array (wxyz), optional |
None
|
ax
|
Optional[Any]
|
Matplotlib 3D axes, created if None |
None
|
title
|
str
|
Plot title |
'SE(3) trajectory'
|
show_orientation
|
bool
|
If True, show orientation frames or cubes |
False
|
vis_type
|
str
|
"arrow" for coordinate frames, "cube" for oriented boxes |
'arrow'
|
box_size
|
tuple
|
Size of cubes (if vis_type="cube") |
(0.03, 0.03, 0.03)
|
color
|
str
|
Trajectory line color |
'b'
|
alpha
|
float
|
Transparency for cubes |
0.7
|
num_frames
|
int
|
Number of orientation samples to show along trajectory |
8
|
label
|
Optional[str]
|
Legend label for trajectory |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Matplotlib axes |
Source code in src/dhb_xr/visualization/plot.py
Overview
Utilities for plotting and visualizing DHB trajectories and invariants.
Main Functions
plot_se3_trajectory
plot
Plot SE(3) trajectories and invariant sequences with cubes and coordinate frames.
Functions
draw_box
Draw a 3D oriented box (cuboid) at the given center with the given rotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Matplotlib 3D axes |
required | |
center
|
ndarray
|
(3,) position of box center |
required |
rotation_matrix
|
ndarray
|
(3, 3) rotation matrix |
required |
size
|
tuple
|
(width, height, depth) of box |
(0.05, 0.05, 0.05)
|
color
|
str
|
Face color |
'blue'
|
alpha
|
float
|
Transparency |
0.3
|
Source code in src/dhb_xr/visualization/plot.py
draw_frame
Draw a coordinate frame (x=red, y=green, z=blue arrows) at the given pose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Matplotlib 3D axes |
required | |
position
|
ndarray
|
(3,) position of frame origin |
required |
rotation_matrix
|
ndarray
|
(3, 3) rotation matrix |
required |
length
|
float
|
Length of arrows |
0.05
|
linewidth
|
float
|
Line width |
2.0
|
Source code in src/dhb_xr/visualization/plot.py
plot_invariants
Plot linear and angular invariant time series.
Source code in src/dhb_xr/visualization/plot.py
plot_se3_trajectories
plot_se3_trajectories(
trajectories,
ax=None,
show_orientation=True,
vis_type="cube",
box_size_scale=0.05,
num_frames=6,
title="SE(3) Trajectories",
show_legend=True,
)
Plot multiple SE(3) trajectories with orientation visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trajectories
|
Union[List[Dict], Dict[str, Dict]]
|
List of dicts with 'positions' and 'quaternions', or dict of name -> trajectory |
required |
ax
|
Optional[Any]
|
Matplotlib 3D axes |
None
|
show_orientation
|
bool
|
Show orientation cubes/frames |
True
|
vis_type
|
str
|
"cube" or "arrow" |
'cube'
|
box_size_scale
|
float
|
Size of cubes |
0.05
|
num_frames
|
int
|
Number of orientation samples per trajectory |
6
|
title
|
str
|
Plot title |
'SE(3) Trajectories'
|
show_legend
|
bool
|
Show legend |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
Matplotlib axes |
Source code in src/dhb_xr/visualization/plot.py
plot_se3_trajectory
plot_se3_trajectory(
positions,
quaternions=None,
ax=None,
title="SE(3) trajectory",
show_orientation=False,
vis_type="arrow",
box_size=(0.03, 0.03, 0.03),
color="b",
alpha=0.7,
num_frames=8,
label=None,
)
Plot 3D position trajectory with optional orientation visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
(N, 3) position array |
required |
quaternions
|
Optional[ndarray]
|
(N, 4) quaternion array (wxyz), optional |
None
|
ax
|
Optional[Any]
|
Matplotlib 3D axes, created if None |
None
|
title
|
str
|
Plot title |
'SE(3) trajectory'
|
show_orientation
|
bool
|
If True, show orientation frames or cubes |
False
|
vis_type
|
str
|
"arrow" for coordinate frames, "cube" for oriented boxes |
'arrow'
|
box_size
|
tuple
|
Size of cubes (if vis_type="cube") |
(0.03, 0.03, 0.03)
|
color
|
str
|
Trajectory line color |
'b'
|
alpha
|
float
|
Transparency for cubes |
0.7
|
num_frames
|
int
|
Number of orientation samples to show along trajectory |
8
|
label
|
Optional[str]
|
Legend label for trajectory |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Matplotlib axes |
Source code in src/dhb_xr/visualization/plot.py
Usage Example
from dhb_xr.visualization.plot import plot_se3_trajectory
import matplotlib.pyplot as plt
# Plot trajectory
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='3d')
plot_se3_trajectory(
ax, positions, quaternions,
color='blue', label='Trajectory'
)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()