• Home
  • About
    • Rutvi Padhy photo

      Rutvi Padhy

      A blog about tech-stuff and my obsession with them.

    • Learn More
    • Twitter
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Pygame Physics Simulations

20 Jan 2019

Reading time ~2 minutes

This project comprises of three, simple and interactive, physical simulations built using Python and Pygame. These simulations have been captioned Falling Balls, Discs on Table and Coalescence of Particles, respectively. One can understand the concepts used in the implementation of these three simulations by refering to a standard XI Physics textbook.

Like I said, the technology used in this project is limited to Python and Pygame. Some formulas that play an important role in the implementation of this project include the following :

1) To determine velocity of balls after collision…

v1 = (m1 – m2 / m1 + m2) * u1 + (2 * m2 / m1 + m2) * u2

v2 = (m2 – m1 / m1 + m2) * u2 + (2 * m1 / m1 + m2) * u1

(coefficient of elasticity (e) = 1)

The above formula has been derived from the equations given below : m1 * u1 + m2 * u2 = m1 * v1 + m2 * v2 (conservation of momentum)

1/2 * m1 * u1 * u1 + 1/2 * m2 * u2 * u2 = 1/2 * m1 * v1 * v1 + 1/2 * m2 * v2 * v2 (conservation of kinetic energy)

2) To estimate force of attraction between two particles…

F = G * m1 * m2 / r * r

3) To find position and velocity of the new particle after coalescence of two particles…

x = (m1 * x1 + m2 * x2) / m1 + m2

y = (m1 * y1 + m2 * y2) / m1 + m2

v = (m1 * v1 + m2 * v2) / m1 + m2

If you wish to study this project more thoroughly, please check out the project here.

Meanwhile, I have some screenshots that you can view to see how these simulations look!

1) balls.py

2) discs.py

3) coalescence.py

And that’s all!

Thank you.



pygamephysicssimulations Share Tweet +1