Some animations around physics

Although I’m not much of a physicist, I am always fascinated with how simple laws, such as Newton’s, can create beautiful and complex movements. I tried to illustrate this by working out little simulations of basic physical models: particles elastic collision, free fall and pendulum evolution.

My goal with this project was not to have an absolutely accurate simulation; instead, I’d rather favor nice visuals. However, computations are based on common Newtonian physics: the direct relation between speed and position, the influence of friction and collision on velocity, gravity and reaction…

The graphics tend to be (overly?) simplistic so you can focus more on the harmony of physics itself! Simulations are made in boxes filled with particles that may or may not collide with each other, and bounce off the borders of the box.

[projectinfo languages=”python” team=”1″ duration=”4 days”]

You can download the Python code to create animations like the one above here. Each script can be run with a few options to modify physical parameters, and the --help command gives you some pointers as to how to use them. The folder also provides some examples of results you can obtain by twitching these settings. This project uses the NumPy and Matplotlib Python libraries.

Basic physics… but physics nonetheless!

As mentioned before, I did make a few approximations in my code, but simulations still follow the laws of physics.

For example, the ‘Collisions’ example (in the script) relies on a usual lightweight computation of elastic collisions, where you consider each particle in your box and see if it touches another: whenever it does, both apply a force on the other one and they get pushed apart along a line that is perpendicular to their collision plane. You can see some examples in the video at the beginning of the article.

The ‘Fall’ simulation depicts a very simple physical problem, the free fall, that every student who has done scientific studies has probably seen multiple times in his or her life. The question you are asked in this kind of exercises is basically: how does gravity act on an object? How does its position evolve in time when only considering this force? (Spoilers: objects usually fall, actually.) This makes for some nice visuals, with small particles bouncing around as they hit the ground and there is the reaction force:

Then, there are more complex problems like the movement of a pendulum. Even if equations are not easy at first, you can work around some difficulties by approximating a few things. In particular, angles computation can quickly become a headache, so you usually suppose they are small enough to simplify this, and eventually you can end up with swinging balls like this:

In my scripts, I use a custom Pendulum object that can have several hinges – or handle points – to create more complex structures. In the video, there are three pendulums with only one hinge (i.e. the end of the pendulum, directly connected by a rigid tube to the hang point) and one pendulum with two hinges. We see that the intermediary point creates a much more complicated movement.

You can even create longer chains by adding hinges:

Free code & Future developments

This first version was developed in a few days and is far from perfect! I plan to continue this project and think of other nice physical situations that I found graceful and elegant.

Hopefully, there are enough comments and info in the file to make it usable, but there is a lot of room for improvement. The code is, as always, under CC BY-NC-SA License, so feel free to look at it and modify it any way you want, as long as you keep the author name somewhere and you don’t sell it to the highest bidder!

Leave a Reply

Your email address will not be published. Required fields are marked *