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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您正在寻找一些看起来真实并且相当快的游戏物理(碰撞、变形、重力等),请考虑重复使用一些物理引擎库。
作为第一个参考,您可能需要查看 pymunk,它是 Chipmunk 2D 物理库。 您可以在维基百科中找到各种开源物理引擎(2D 和 3D)的列表。
如果您正在寻找物理上正确的模拟,无论您想使用什么语言,它都会慢得多(几乎不是实时的),并且您需要使用一些数值分析软件(并且可能自己编写一些东西)。 确切的答案取决于您想要解决的问题。 这是一个相当复杂的(数学)领域。
例如,如果您需要进行连续介质力学或电磁学的模拟,您可能需要有限差分、有限体积或有限元方法。 对于 Python,有一些现成的库,例如: FiPy (FVM) 、GetFem++ (FEM)、FEniCS/DOLFIN (FEM),以及其他一些。
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.
这是一些简单的天文学相关的Python。 这是来自同一个人的硬核代码。
Eagleclaw 使用一些 Python 求解并绘制各种双曲方程。 然而,大部分代码是用 Fortran 编写的来进行计算,并用 Python 来绘制结果。 如果您正在学习物理,那么您可能必须习惯这种 Fortran 包装的代码。 这是现实。 但我猜这并不是你真正想要的。 好处是它以文字编程风格记录,因此应该是可以理解的。
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.
也许PyODE?
Maybe PyODE?
我听说过 PyBox2D,它是真正的不错的 Box2D。 引用该网站:
I've heard of PyBox2D, which is a port of the really nice Box2D. To quote the site: