I am a total beginner in both simulations so this question might be silly. If so, please feel free to edit it. I am trying to simulate the following scenario in Python. I randomly place a few small particles in a 2D field with fixed dimentions. Each particle has a radius of effect r. If the first particle has the second one within its radius of effect, then a force has to be applied on both the particles (the effect that the first one has on the second and vice versa) and my force function is defined as:
f(i,j)_n = (r - |pi_n - pj_n|)((pj_n - pi_n)/|pi_n - pj_n|)
where n is the time step currently, pi_n represents the position of i at time step n and || represents magnitude calculation and (pj_n - pi_n) represents vector subtraction.
I was wondering if there are any libraries that simplify this stuff for me. All I need is basically the following:
time-step particle position(x,y)
Does anyone have some suggestions for me please?
I really like the pymunk physics library, a wrapper for the chipmunk physics library.
First of all, the library needs to be initialized:
To achieve something the likes you have requested you have to create a
Bodyand aCircleshape for each particle you wish to create.The particles will not collide with each other, beacause the
sensorflag is set toTrue. The radius is now somewhat of an area of influence.Now, we create a callback function for particles which have an overlapping area of influence:
The callback is set in the
space:Of course, the
spacehas to be “stepped” for each time-frame:I hope this was somewhat understandable and helpful.