Skip to content

Simulation of collisions with variable coefficients of restitution. Built using pygame in Python.

Notifications You must be signed in to change notification settings

divyajeettt/collision-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

collision-simulator

About collision-simulator

collision-simulator is quite literally a simulation of collisions, with variable coefficients of restitution, built using pygame in Python.

Date of creation: 03 September, 2021

It is an interactive simulation where the user spawns balls on the screen, that collide with each other and with walls (having infinite mass). The collisions are handled using real collision mechanics.

Features

  • Spawn balls of different radii and variable densities
  • Turn gravity (of variable strength) ON and OFF, and change its direction
  • Walls of infinite mass
  • Different beep sounds for collisions (depending upon their masses)
  • Ability to view the current state of any ball (by clicking it)
  • Generation of logs

Controls

Check the main controls in controls.txt. Additional controls are as follows:

  • CTRL: To see the controls
  • L: Log the current state of the balls

Edit the logging settings

To modify the level of the logger, modify:

logging.basicConfig(
    filename="collisions.log", level=logging.INFO, format=LOG_FORMAT
)

on Line 56 of main.py to:

logging.basicConfig(
   filename="collisions.log", level=LEVEL, format=LOG_FORMAT
)

where LEVEL can be one of:

  • logging.INFO
  • logging.DEBUG
  • logging.WARNING
  • logging.ERROR
  • logging.CRITICAL

Run

To run, clone the repository on your device, navigate to the folder, and execute:

python3 main.py

Footnotes and Issues

  • Beep sounds get delayed when a large number of collisions occur simultaneously.
  • If a Ball is moving too fast, it may be able to escape the boundary. This is possibly due to not registering its collision with the wall as its updated position stands outside the boundary. It seems like the issue can be solved by checking if the 'next' position of the Ball is outside the Box, and if so, reflecting it off of the wall at that instant of time.
  • For lower restitutions of collision and for fast velocities, two or more balls may get stuck together.

About

Simulation of collisions with variable coefficients of restitution. Built using pygame in Python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages