Pedestrian behavior simulation

Hi, I have a project to simulate the pedestrian behavior based on the social force model. I have started with creating the pedestrian class. the pedestrian behavior is controlled by certain forces, accelerate toward target, respect others space, avoid obstacle, and attraction forces.
I started with creating the pedestrian class. this is my first time to use processing platform and I am a little bit lost! I need some guidance.
any hints or guidance will be highly appreciated.
when I use the python mode, it’s a little bit challenging because the libraries like numpy and pandas are not available, is there a way to overcome this challenge?

1 Like

I cannot help in regards to numpy or pandas for the Python mode. I would suggest you review the Processing documentation for Python mode and become aware of the limitations before you engage in this project using Processing in python mode.

If Pandas/numpy is essential for your project, I suggest you use Python visual libraries like vpython. I am not sure what is the current state of that project ad you will need to check with the Python community.

If you want to use Processing in Java mode, I suggest you post a minimum amount of code showing your current issue. In Processing, I have used OOP for simulating distal force interactions, similar to what you have done here. I suggest you explore the examples here to explore core concepts, specially this one with class definitions and inter-particle interaction.

Kf

Welcome @emyou

Here are a couple of (Python) options you might explore:

  • you can look at using some Java alternative (in Python mode) for the libraries you need, like ND4J
  • or some pure Python libraries (with no C bindings), like tinynumpy

Alternatively, you could use another Python variant of Processing, like p5py (that will work with any Python library).

Of course, there’s PVector for working with vectors (if you aren’t using it already).

3 Likes

Thank you for your response.
I am trying to cut the project into smaller pieces.
1-I just want to see a particle on my screen.
2-create an array of particles
3-create a path that these particles can follow.

I started with creating a mover class. using this code:

class Mover(object):

def __init__(self, m, x, y):
    # Mass is tied to size.
    self.mass = m
    self.location = PVector(x, y)
    self.velocity = PVector(0, 0)
    self.acceleration = PVector(0, 0)

# Newton's 2nd law: F = M * A
# or A = F / M
def applyForce(self, force):
    # Divide by mass.
    f = PVector.div(force, self.mass)
    # Accumulate all forces in acceleration.
    self.acceleration.add(f)

def update(self):
    # Velocity changes according to acceleration.
    self.velocity.add(self.acceleration)
    # Location changes by velocity.
    self.location.add(self.velocity)
    # We must clear acceleration each frame.
    self.acceleration.mult(0)

# Draw Mover.
def display(self):
    stroke(255)
    strokeWeight(2)
    fill(255, 200)
    ellipse(self.location.x, self.location.y,
            self.mass * 16, self.mass * 16)

from mover import Mover

movers = [None] * 10

def setup():
size(640, 360)

def draw():
background(0)
# Draw water.

mover.update()
mover.display()
mover.checkEdges()
fill(255)

I got this error:
global name mover is not defined

what’s wrong with this code?

There are a few things wrong here. This revised and commented code should help clarify what’s wrong:

from mover import Mover

# you must populate the list/array somehow, for example:
movers = [
  Mover(10, 50, 200),
  Mover(5, 100, 150),
  Mover(1, 200, 150)
]

# this force is applied to the movers
wind = PVector(0.1, -0.05)

def setup():
    size(640, 360)

def draw():
    background(0)
    fill(255)
    
    # loop through the movers to update and display each one
    for mover in movers:
        mover.applyForce(wind)
        mover.update()
        mover.display()

Do you have any plan for how you might approach the “create a path that these particles can follow” part?

2 Likes

I am still searching for a plan for the path code.
This is my first time with processing, things are very new to me.
if you have any insight or hint, I will be so grateful if you share it.
Thanks