3Diffusion: A Brownian Motion Simulation
October 21, 2025
Hello! I wanted to use this post to highlight a little physics simulation I built earlier this year and have been iterating on over the past few months. The simulation should be running in the box below. You can click on the simulation window to move around the camera and hit the ESC key to exit when you’re done.
The Physics
As you can see this program simulates particles (or “balls”) colliding in a box in 3D space. The collisions are fully elastics, meaning no energy is lost during collisions, momentum is simply transferred between the different particles.
While most of the particles have the same size and mass, you can see there is a large red ball which has 4 times the radius and 4 times the mass of the smaller blue balls (technically if all the particles had the same density then the red ball should have 64 times the mass, so let’s assume the red ball is made of a lighter, less dense materials). The red ball’s position is tracked and drawn as it collides with the smaller particles and bounces around the room.
I wanted to have one particle larger than the rest to showcase the process of Brownian motion, which describes the seemingly random motion of particles suspended in a medium (e.g., a dust particle floating in water or air). Brownian motion is also the physical process underlying diffusion, hence the name 3Diffusion.
There are many great simulations of Brownian motion online already, including one on the Brownian motion wikipedia page. A personal favorite of mine is this one by MinuteLabs: labs.minutelabs.io/Brownian-Motion.
However I noticed all existing simulations I could find simulate the process in 2D, so I thought I could add something by showing what the process looks like in 3D space.
For anyone interested in the code behind the simulation see the following repository on my personal GitHub account: github.com/PumpkinFan/3Diffusion