Python 中物理的简单模拟?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/501940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 20:15:19  来源:igfitidea点击:

Simple simulations for Physics in Python?

pythonmodelingsimulation

提问by Léo Léopold Hertz ??

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?

在 Python 中进行此类模拟时,您最喜欢的图书馆/互联网页面是什么?

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

我知道一点 Simpy、Numpy 和 Pygame。我想得到关于它们的例子。

回答by sastanin

If you are looking for some gamephysics (collisions, deformations, gravity, etc.) which looksreal and is reasonably fastconsider re-using some physics enginelibraries.

如果您正在寻找一些看起来真实且相当快的游戏物理(碰撞、变形、重力等),请考虑重新使用一些物理引擎库。

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

作为第一个参考,您可能需要查看pymunk,它是Chipmunk2D 物理库的 Python 包装器。您可以在 Wikipedia 中找到各种开源物理引擎(2D 和 3D)的列表。

If you are looking for physically correctsimulations, no matter what language you want to use, it will be much slower(almost never real-time), and you need to use some numerical analysissoftware (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.

例如,如果您需要在连续介质力学或电磁学中进行模拟,您可能需要有限差分、有限体积或有限元方法。对于 Python,有一些现成的库,例如:FiPy(FVM)、GetFem++(FEM)、FEniCS/DOLFIN(FEM) 等。

回答by Alex

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

这是一些与天文学相关的简单python。这是同一个人的核心代码

And Eagleclawsolves 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.

Eagleclaw解决了和情节不同双曲型方程组使用一些蟒蛇。但是,大部分代码是用 Fortran 编写的来进行计算,而用 Python 来绘制结果。如果您正在学习物理,那么您可能必须习惯这种 Fortran 包装的代码。这是一个现实。但这并不是我真正想要的。好消息是它以文学编程风格记录,所以它应该是可以理解的。

回答by nikow

Maybe PyODE?

也许PyODE

回答by Nikhil Chelliah

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

我听说过PyBox2D,它是非常好的 Box2D 的一个端口。引用该网站:

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.

Box2D 是一个功能丰富的 2d 刚体物理引擎,由 Erin Catto 用 C++ 编写。它已被用于许多游戏,包括 Crayon Physics Deluxe,2008 年独立游戏节大奖的获得者。