Skip to content

Latest commit

 

History

History
86 lines (69 loc) · 2.66 KB

README.md

File metadata and controls

86 lines (69 loc) · 2.66 KB

Ball Collision Simulator

(Package ballcollide)

This package simulates the elastic, inelastic, or partially elastic collisions between two balls using the VPython library. It contains modules to define the physical and visual properties of the balls, perform the simulation, and visualize the collision in a 2D space.

Here are the runtime options: python ball_collision_sim.py -h:

usage: ball_collision_sim.py [-h] [--test] [--no_gui]

Ball Collision Simulator

options:
  -h, --help  show this help message and exit
  --test      Run with pre-defined test case
  --no_gui    Run without GUI

Modules:

  • ball_collision_sim: The main module that runs the system. It manages the entire simulation process, including initialization, running the simulation, and handling collisions.
  • ball_sim_enums: Contains enums used by the system.
  • ball_sim_parameters: Contains classes to store parameter data needed by the system.
  • ball_sim: Contains the Ball class which represents the balls in the system.
  • ball_sim_info: Contains classes to hold info/state of the system.
  • tests: Tests for the Ball Collision Simulator system.

Documentation

For detailed API documentation, see: Ball Collision Simulator API Documentation

To Use

  1. Clone this repository.
  2. Run the setup script: setup.sh. (This will install needed dependencies)
  3. Run python ball_collision_sim.py. (With or without command line options)

Sample Screenshot

***************************************************
Initial Conditions:

Ball 1:
  Mass: 1 kg
  Radius: 0.5 m
  Position: (0.4, 3)
  Velocity: (0, -2), or 2 m/s at -90°
  Momentum: (0, -2), or 2 N⋅s at -90°
  Kinetic Energy: 2 J
Ball 2:
  Mass: 2 kg
  Radius: 0.63 m
  Position: (-0.5, -3)
  Velocity: (0, 1), or 1 m/s at 90°
  Momentum: (0, 2), or 2 N⋅s at 90°
  Kinetic Energy: 1 J

Initial Distance: 6.07 m
Sum of Radii: 1.13
Total Momentum: (0, 0), or 0 N⋅s at 0°
Total Kinetic Energy: 3 J

t=0s: Balls are Converging at: 3 m/s
t=1.78s: Balls are Diverging at: 3 m/s

Collision occurred at time: 1.78 secs

Post Collision Conditions:

Ball 1:
  Mass: 1 kg
  Radius: 0.5 m
  Position: (0.4, -0.56)
  Velocity: (1.91, -0.601), or 2 m/s at -17.5°
  Momentum: (1.91, -0.601), or 2 N⋅s at -17.5°
  Kinetic Energy: 2 J
Ball 2:
  Mass: 2 kg
  Radius: 0.63 m
  Position: (-0.5, -1.22)
  Velocity: (-0.954, 0.301), or 1 m/s at 163°
  Momentum: (-1.91, 0.601), or 2 N⋅s at 163°
  Kinetic Energy: 1 J

###################################################