A simple two-dimensional Brownian motion animation


This code continues the previous blog post on two-dimensional collisions to model Brownian motion. The code is on my GitHub page.

The core classes, PeriodicParticle and PeriodicSimulation are derived from the original Particle and Simulation classes to allow periodic boundary conditions: instead of bouncing off the walls, the particles move through them and reappear at the other side of the domain.

In the example given here, the mass of the large particle is set to be equal to that of the small ones, so that it gains enough momentum quickly to be seen to move in the animation. This can be altered by setting the mass property of the PeriodicParticle class.

enter image description here

Current rating: 3.6


Comments are pre-moderated. Please be patient and your comment will appear soon.

Anandaram Mandyam 1 year, 9 months ago

When I run this script thru Spyder in my PC under anaconda py3.7 I get this error message:
File "D:/PyScripts_01/ChristianHill_SciPython/Brownian2D.py", line 58, in init_particles
while not self.place_particle(radius, styles):
AttributeError: 'PeriodicSimulation' object has no attribute 'place_particle'
Pl suggest remedy.
Thanks in advance

Link | Reply
Current rating: 1

christian 1 year, 9 months ago

Sorry! This is my fault completely: I forgot to commit the updated collision.py file to my repo. It should be there now – can you try again and let me know if you have any more problems?

Link | Reply
Currently unrated

Anandaram Mandyam 1 year, 9 months ago

With the revised collision.py script the 2D brownian file is working fine although the animation appears to freeze after some time. I am trying to tweak some parameters to avoid it from happening.
Thanks anyway.

Link | Reply
Current rating: 5

Chenghung 1 day, 19 hours ago


I want to thank you for your contribution and this does help my course final project. I Will definitely cite this course and recommend it to my classmates.

Link | Reply
Currently unrated

Chenghung 1 day, 18 hours ago

I notice in the end the particles will overlap.

Link | Reply
Currently unrated

New Comment


required (not published)