有哪些算法可以让我模拟行星物理?
我有兴趣制作一个“太阳系”模拟器,它可以让我模拟行星和恒星的旋转力和引力。
我想说的是,模拟我们的太阳系,并以不同的速度模拟它(即观察地球和其他行星绕太阳旋转数天、数年等)。我希望能够添加行星并改变行星质量等,看看它会如何影响系统。
有谁有任何资源可以为我指明编写此类模拟器的正确方向吗?
是否有任何现有的物理引擎是为此目的而设计的?
I'm interested in doing a "Solar System" simulator that will allow me to simulate the rotational and gravitational forces of planets and stars.
I'd like to be able to say, simulate our solar system, and simulate it across varying speeds (ie, watch Earth and other planets rotate around the sun across days, years, etc). I'd like to be able to add planets and change planets mass, etc, to see how it would effect the system.
Does anyone have any resources that would point me in the right direction for writing this sort of simulator?
Are there any existing physics engines which are designed for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
这是这里的所有内容,总的来说,是 Jean Meeus 写的所有内容。
(来源:willbell.com)
It's everything here and in general, everything that Jean Meeus has written.
(source: willbell.com)
您需要了解并理解牛顿万有引力定律和开普勒行星运动定律。这两个都很简单,我相信你即使没有在高中学习过,也听说过它们。最后,如果您希望模拟器尽可能准确,您应该熟悉 n-Body问题。
你应该从简单的开始。尝试制作一个
太阳
对象和一个围绕它旋转的地球
对象。这应该给你一个非常坚实的开始,并且从那里很容易扩展。行星物体看起来像这样:只要记住
F = MA
其余的只是无聊的数学:PYou need to know and understand Newton's Law of Universal Gravitation and Kepler's Laws of Planetary Motion. These two are simple and I'm sure you've heard about them, if not studied them in high school. Finally, if you want your simulator to be as accurate as possible, you should familiarize yourself with the n-Body problem.
You should start out simple. Try making a
Sun
object and anEarth
object that revolves around it. That should give you a very solid start and it's fairly easy to expand from there. A planet object would look something like:Just remember that
F = MA
and the rest just just boring math :P这是关于一般 N 体问题的一个很棒的教程。
http://www.artcompsci.org/#msa
它是使用 Ruby 编写的,但很容易映射到其他语言等。它涵盖了一些常见的集成方法;前向欧拉、蛙跳和厄米。
This is a great tutorial on N-body problems in general.
http://www.artcompsci.org/#msa
It's written using Ruby but pretty easy to map into other languages etc. It covers some of the common integration approaches; Forward-Euler, Leapfrog and Hermite.
您可能想看看 Celestia,一个自由空间模拟器。我相信您可以使用它来创建虚构的太阳系,并且它是开源。
You might want to take a look at Celestia, a free space simulator. I believe that you can use it to create fictitious solar systems and it is open source.
您需要实现的只是适当的微分方程(开普勒定律)并使用龙格-库塔。 (至少这对我有用,但可能有更好的方法)
网上有很多这样的模拟器。
这是一个用 500 行 C 代码实现的简单代码。 (运动算法要少得多)
http://astro.berkeley.edu/~dperley/programs/ssms.html< /a>.
另请检查:
http://en.wikipedia.org/wiki/Kepler_problem
http://en.wikipedia.org/wiki/Two-body_problem
http://en.wikipedia.org/wiki/N-body_problem
All you need to implement is proper differential equation (Keplers law) and using Runge-Kutta. (at lest this worked for me, but there are probably better methods)
There are loads of such simulators online.
Here is one simple one implemented in 500lines of c code. (montion algorhitm is much less)
http://astro.berkeley.edu/~dperley/programs/ssms.html.
Also check this:
http://en.wikipedia.org/wiki/Kepler_problem
http://en.wikipedia.org/wiki/Two-body_problem
http://en.wikipedia.org/wiki/N-body_problem
在物理学中,这被称为N 体问题。它之所以出名,是因为对于一个拥有三个以上行星的系统,你无法手动解决这个问题。幸运的是,您可以通过计算机轻松获得近似解。
可以在此处找到一篇关于从头开始编写此代码的好论文。
然而,我觉得这里警告很重要。您可能不会得到您期望的结果。如果你想了解:
问题是这样的。
是的,现代天文学家关心土星的质量如何改变地球绕太阳运行的轨道。但这是一个非常小的影响。如果你要绘制一颗行星绕太阳运行的路径,那么太阳系中是否还有其他行星并不重要。太阳太大了,它会淹没所有其他引力。唯一的例外是:
需要明确的是,是的,您将能够计算行星之间的一些相互作用。但不,如果你创建一个真实的太阳系,这些相互作用对于肉眼来说并不重要。
尝试一下,然后就知道了!
In physics this is known as the N-Body Problem. It is famous because you can not solve this by hand for a system with more than three planets. Luckily, you can get approximate solutions with a computer very easily.
A nice paper on writing this code from the ground up can be found here.
However, I feel a word of warning is important here. You may not get the results you expect. If you want to see how:
The problem is this.
Yeah, modern astronomers are concerned with how Saturn's mass changes the Earth's orbit around the Sun. But this is a VERY minor effect. If you are going to plot the path of a planet around the Sun, it will hardly matter that there are other planets in the Solar System. The Sun is so big it will drown out all other gravity. The only exceptions to this are:
To be clear, yes, you will be able to calculate some interactions between planets. But no, these interactions will not be significant to the naked eye if you create a realistic Solar System.
Try it though, and find out!
查看 nMod,这是一个用 C++ 编写并使用 OpenGL 的 n 体建模工具包。它附带了一个相当完善的太阳系模型,并且应该很容易修改。此外,他还有一个关于 n 体模拟的非常好的 wiki。创建此程序的同一个人也在制作一个名为 Moody,但似乎还没有那么远。
此外,如果您打算使用多个对象进行 n 体模拟,那么您应该真正查看 快速多极法(也称为快速多极算法)。它可以将计算量从 O(N^2) 减少到 O(N),从而真正加快模拟速度。它也是20世纪最成功的十大算法之一,根据本文作者的说法。
Check out nMod, a n-body modeling toolkit written in C++ and using OpenGL. It has a pretty well populated solar system model that comes with it and it should be easy to modify. Also, he has a pretty good wiki about n-body simulation in general. The same guy who created this is also making a new program called Moody, but it doesn't appear to be as far along.
In addition, if you are going to do n-body simulations with more than just a few objects, you should really look at the fast multipole method (also called the fast multipole algorithm). It can the reduce number of computations from O(N^2) to O(N) to really speed up your simulation. It is also one of the top ten most successful algorithms of the 20th century, according to the author of this article.
模拟行星物理的算法。
这是我的 Android 应用程序中开普勒部件的实现。主要部分位于我的网站上,您可以下载整个源代码: http://www.barrythomas .co.uk/keppler.html
这是我在轨道上的“下一个”位置绘制行星的方法。想象一下这些步骤就像在一个与您要跟踪的行星具有相同周期的圆上绕圈行走一样,一次一度。在该方法之外,我使用全局双精度作为步数计数器 - 称为 dTime,其中包含多个旋转度数。
传递给该方法的关键参数包括 dEccentricty、dScalar(比例因子,以便轨道全部适合显示)、dYear(以地球年为单位的轨道持续时间)以及确定轨道方向,以便近日点位于正确的位置可以说,表盘上的 dLongPeri - 近日点经度。
drawPlanet:
上面的方法调用另外两个方法,它们提供E(平均异常)和r(在其末端找到行星的向量的长度)的值。
getE:
getRfromE:
Algorithms to simulate planetary physics.
Here is an implementation of the Keppler parts, in my Android app. The main parts are on my web site for you can download the whole source: http://www.barrythomas.co.uk/keppler.html
This is my method for drawing the planet at the 'next' position in the orbit. Think of the steps like stepping round a circle, one degree at a time, on a circle which has the same period as the planet you are trying to track. Outside of this method I use a global double as the step counter - called dTime, which contains a number of degrees of rotation.
The key parameters passed to the method are, dEccentricty, dScalar (a scaling factor so the orbit all fits on the display), dYear (the duration of the orbit in Earth years) and to orient the orbit so that perihelion is at the right place on the dial, so to speak, dLongPeri - the Longitude of Perihelion.
drawPlanet:
The method above calls two further methods which provide values of E (the mean anomaly) and r, the length of the vector at the end of which the planet is found.
getE:
getRfromE:
看起来很难,需要很强的物理知识,但实际上很简单,你只需要知道 2 个公式和对向量的基本了解:
质量为 m1 和 m2 的行星 1 和行星 2 之间的吸引力(或引力)它们之间的距离d:Fg = G*m1*m2/d^2; Fg = m*a。 G是一个常数,通过代入随机值来求得,使得加速度“a”不会太小,也不会太大,大约为“0.01”或“0.1”。
如果您有在该时刻作用在当前行星上的总矢量力,您可以找到瞬时加速度 a=(总力)/(当前行星的质量)。如果你有当前的加速度、当前的速度和当前的位置,你可以找到新的速度和新的位置
如果你想看起来真实,你可以使用以下超级简单的算法(伪代码):
It looks like it is very hard and requires strong knowledge of physics but in fact it is very easy, you need to know only 2 formulas and basic understanding of vectors:
Attractional force (or gravitational force) between planet1 and planet2 with mass m1 and m2 and distance between them d: Fg = G*m1*m2/d^2; Fg = m*a. G is a constant, find it by substituting random values so that acceleration "a" will not be too small and not too big approximately "0.01" or "0.1".
If you have total vector force which is acting on a current planet at that instant of time, you can find instant acceleration a=(total Force)/(mass of current planet). And if you have current acceleration and current velocity and current position, you can find new velocity and new position
If you want to look it real you can use following supereasy algorythm (pseudocode):
如果您要模拟物理,我强烈推荐 Box2D。
这是一个很棒的物理模拟器,通过物理模拟,可以真正减少您所需的样板数量。
If you're simulating physics, I highly recommend Box2D.
It's a great physics simulator, and will really cut down the amount of boiler plate you'll need, with physics simulating.
Bate、Muller 和 White 的《天体动力学基础》 仍然是我的必读内容本科航空航天工程师的母校。这往往涵盖地球轨道上物体的轨道力学……但这可能是您开始理解所需的物理和数学水平。
+1 @Stefano Borini 对“Jean Meeus 所写的所有内容”的建议。
Fundamentals of Astrodynamics by Bate, Muller, and White is still required reading at my alma mater for undergrad Aerospace engineers. This tends to cover the orbital mechanics of bodies in Earth orbit...but that is likely the level of physics and math you will need to start your understanding.
+1 for @Stefano Borini's suggestion for "everything that Jean Meeus has written."