PedestrianDynamics / PedPy

Analysis of pedestrian dynamics based on trajectory files.
https://pedpy.readthedocs.io
MIT License
17 stars 10 forks source link

Visual Representation of Traversable Areas and Multiple Areas #342

Closed LilQuacky closed 4 months ago

LilQuacky commented 4 months ago

Currently, I am employing MeasurementArea (improperly) to visualize the final targets within my rooms. I don't require any calculations within them; they merely serve to enhance the aesthetics and faithfulness to the environment I've created in Godot.

I'm exploring alternatives as I solely need them for aesthetic purposes. Additionally, some rooms feature two final targets, rendering the use of MeasurementArea impractical due to its non-iterative nature.

Here the code and the results:

from pedpy import WalkableArea
from pedpy import plot_measurement_setup
from pedpy import MeasurementArea, MeasurementLine
import matplotlib.pyplot as plt

def plot_trajectories(trajectories: Collection[TrajectoryData], walkable_area: WalkableArea, final_target: MeasurementArea) -> None:

for traj, color in zip(trajectories, ['#FF0000', '#0000FF', '#00FF00', '#FFFFFF']):
    plot_measurement_setup(
        walkable_area=walkable_area,
        measurement_areas=[final_target], #using MeasurementArea as placeholder to show the final target of the level
        traj=traj,
        traj_color=color,
        traj_alpha=0.5,
        traj_width=1,
        ma_line_width=0.1,
        ma_alpha=0.5,
        ma_line_color='#a464ac',
        ma_color='#68006c',
        ml_width=2.5,
        ml_color='#a464ac'
    ).set_aspect("equal")

curve_c_area = WalkableArea(
    # Complete area (outer boundary)
    [
        (10, -10),
        (10, 10),
        (-10, 10),
        (-10, -10),
    ],
  obstacles=[
      # bottom barrier
      [
          (9.999, -6.5),
          (-7, -6.5),
          (-7, 6.5),
          (9.999, 6.5),
          (9.999, 5.5),
          (-6, 5.5),
          (-6, -5.5),
          (9.999, -5.5),
      ],

  ],
)

curve_c_final_target = MeasurementArea(
    [(7.3, 6.5), (9.999, 6.5), (9.999, 9.999), (7.3, 9.999)]
)

curve_c_traj = extract_trajectories(
    Path("../output/pedpy/CurveCBatch.txt")
  )

plot_trajectories(curve_c_traj, curve_c_area, curve_c_final_target)
plt.show()`

image

curvac

Here the representation of an environment with multiple final targets

doppia porta opposta

chraibi commented 4 months ago

Hi, nice visualizations and creative way to use pedpy, even if not what the developers had in mind! ^_^

Additionally, some rooms feature two final targets, rendering the use of MeasurementArea impractical due to its non-iterative nature.

Is this your problem? If so, maybe a workaround might be using the axes argument of plot_measurement_setup.

For example:

fig, ax = plt.subplots(nrows=1, ncols=1)

then plot some polygons (for exists) instead of measurement areas. See for example here.

LilQuacky commented 4 months ago

Thank you! It worked!

output