This repository presents a particle collision simulation using the Leapfrog algorithm to solve the equations of motion. The simulation is implemented with the Pygame library, and the particles interact through elastic collisions.
- Particle movement using the Leapfrog algorithm.
- Vector-based collision handling with velocity and position adjustments.
- Addition of new particles by clicking on the screen.
-
Leapfrog Algorithm:
- Updates the positions and velocities of particles using acceleration and intermediate velocities for greater accuracy.
- Collisions and new trajectories are recalculated using vector algebra.
-
Collisions:
- Detects collisions between particles based on their distance.
- Adjusts velocities according to the laws of conservation of momentum and energy for elastic collisions.
- Prevents overlap by correcting particle positions.
- Mouse: Left-click to add new particles to the screen.
- ESC key: To exit the simulation.
- Particle: A class representing each particle, containing position, velocity, acceleration, color, and radius attributes.
- check_collision: A function that handles collisions between two particles, adjusting velocities and positions.
- Main Loop: Controls particle movement and drawing on the screen, and detects mouse events.
- Python 3.8+
- Pygame 2.0+
- Numpy
- math