/2D-Physics-Engine

Physics_Engine is a python library that allows users to create simple yet realistic simulations of collisions between massive circles and line segments within some boundary conditions.

Primary LanguagePythonOtherNOASSERTION

Physics_Engine is a python library that allows users to create simple yet realistic simulations of collisions between massive circles and line segments within some boundary conditions.

This library provides two main object classes: 'Particle' and 'Line'. Given a set of particles and line segments the main 'Engine' function creates a real-time simulation and graphic animation of the interaction between particles and lines.

Particles will bounce off other particles, lines or boundaries according to newtonian mechanics, preserving energy thanks to the implementation of a Verlet algorithm used to move the particles.

Forwarding
Pachinko

Routing
Closed Circle Boundary

In order to create a particle 'p' one must procede to inicializate as follows

p = Particle(Position, Velocity, Mass, Radius, Color, Dynamic)

In order to create a line segment 'l' one must procede to inicializate as follows

l = Line(Point_A, Point_B)

The environment in which the objects exist must be determined by the user, this includes:

  • Window_Size: Size of the window screen in pixels
  • Background: Function comprised of pygame code to draw anything on the screen background
  • Boundary: Function that changes the position and velocity of particles defining some boundary
  • Force: Function that describes the force felt by a particle

The library includes some predefined functions that could be used to describe the environment

  • Boundaries:
    • Closed_Box_Boundary
    • Periodic_Boundary
    • Closed_Circle_Boundary
  • Circle_Boundary_Background
  • Const_Gravity

This python library allows multiple aplications, including physics simulations with real educational value, a great example might be the simulation presented bellow, with two gases separated by a chamber, blue particles have greater average velocity than red particles. This could be used to demonstrate principles in thermodinamics and statistical physics

Routing
Two Gases

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.