Skip to content

Edu92337/Particle-CollisionSimulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Particle Collision Simulation

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.

Features

  • Particle movement using the Leapfrog algorithm.
  • Vector-based collision handling with velocity and position adjustments.
  • Addition of new particles by clicking on the screen.

How it works

  1. 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.
  2. 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.

Controls

  • Mouse: Left-click to add new particles to the screen.
  • ESC key: To exit the simulation.

Code Structure

  • 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.

Requirements

  • Python 3.8+
  • Pygame 2.0+
  • Numpy
  • math

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages