Interactive Colliding Particle System Simulator
To compile particle-collision.c, type: cc -o particle-collision particle-collision.c -L/System/Library/Frameworks -framework GLUT -framework OpenGL -lm
To run particle-collision.c, type: ./particle-collision
- All particles are equal in size and mass
A particle that lives in a region,
When
a wall collision has occurred.
If
If
If
Where D is the damping coefficient if one exists
Particle A has a position,
Particle B has a position,
Both particles have radius r.
Find the distance between the two particles:
If
Now new velocity vectors need to be calculated.
- Find the normal vector between the two particles:
$\vec{N} = s_A - s_B $ - Get the magnitude of the normal vector by taking the square root of the dot product of the normal vector with itself:
$||N|| = \sqrt {\vec{N} \cdot \vec{N}}$ - Divide the normal vector by its magnitude to get the unit norm vector:
$\vec{n} = \frac{\vec{N}}{||N||}$ - Get the relative velocity between the two particles:
$\vec{V} = v_A - v_B$ - Find the dot product of the unit norm vector and the relative velocity vector:
$vn = \vec{V} \cdot \vec{n}$ - Multiply the resulting dot product with the unit norm vector:
$\vec{VN} = vn * \vec{n}$ - Find the resulting velocities for each particle:
$v_A = (\vec{v_A} - \vec{VN}) * collisionDamping $ $v_B = (\vec{v_B} + \vec{VN}) * collisionDamping $
Interactive options:
- You can grab and throw a particle with the mouse
- 'g' increases upward gravity
- 'h' increases downward gravity
- 'z' increases size of particles
- 'x' decreases size of particles
- 'c' add particle to the system
- 'v' remove particle from system
- 'q' quit program
- 'l' pan camera view clockwise
- 'k' pan camera view counter-clockwise
- 'd' decrease damping coefficient
- 'f' increase damping coefficient
- 'm' toggle on/off mapping the particle velocity to 3D color cube
Rotate View:
Click and Drag Particle:
Increase/Decrease Gravity:
Add Particles:
Remove/Add Particles:
Size Change:
Damping Coefficient Greater Than One: