Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple simulations for Physics in Python?

I would like to know similar, concrete simulations, as the simulation about watering a field here.

What is your favorite library/internet page for such simulations in Python?

I know little Simpy, Numpy and Pygame. I would like to get examples about them.

like image 794
Léo Léopold Hertz 준영 Avatar asked Feb 02 '09 00:02

Léo Léopold Hertz 준영


4 Answers

If you are looking for some game physics (collisions, deformations, gravity, etc.) which looks real and is reasonably fast consider re-using some physics engine libraries.

As a first reference, you may want to look into pymunk, a Python wrapper of Chipmunk 2D physics library. You can find a list of various Open Source physics engines (2D and 3D) in Wikipedia.

If you are looking for physically correct simulations, no matter what language you want to use, it will be much slower (almost never real-time), and you need to use some numerical analysis software (and probably to write something yourself). Exact answer depends on the problem you want to solve. It is a fairly complicated field (of math).

For example, if you need to do simulations in continuum mechanics or electromagnetism, you probably need Finite Difference, Finite Volume or Finite Element methods. For Python, there are some ready-to-use libraries, for example: FiPy (FVM), GetFem++ (FEM), FEniCS/DOLFIN (FEM), and some other.

like image 65
sastanin Avatar answered Sep 26 '22 02:09

sastanin


Here is some simple astronomy related python. And here is a hardcore code from the same guy.

And Eagleclaw solves and plots various hyperbolic equations using some python. However, most of the code is written in Fortran to do the computations and python to plot the results. If you are studying physics though you may have to get used to this kind of Fortran wrapped code. It is a reality. But this isn't really what your looking for I guess. The good thing it that it is documented in a literate programming style so it should be understandable.

like image 43
Alex Avatar answered Sep 26 '22 02:09

Alex


Maybe PyODE?

like image 45
nikow Avatar answered Sep 26 '22 02:09

nikow


I've heard of PyBox2D, which is a port of the really nice Box2D. To quote the site:

Box2D is a feature rich 2d rigid body physics engine, written in C++ by Erin Catto. It has been used in many games, including Crayon Physics Deluxe, winner of the 2008 Independent Game Festival Grand Prize.

like image 37
Nikhil Avatar answered Sep 22 '22 02:09

Nikhil