Modeling of orbits using the laws of physics

Over the past couple of weeks, I have been trying to simulate orbits in modeling the solar system, which I do as part of a university module. To shorten everything, my simulation is written in C ++ using the Ogre3D rendering engine. I tried to realize orbits using Newton’s law of universal gravitation, which made my planet go straight to the sun, go through the sun, and then return to its original position. I also tried the steps in the “Position as a function of time” section of this article, but that didn't help me either.

I control the simulation with a simple Euler integration method. If someone has experience with such a simulation, or just generally knows a lot about these laws of physics, then any help or pointing me in the right direction would be greatly appreciated.

+6
source share
3 answers

You must give the initial velocity of the planet v = (vx, vy, vz), tangent to the desired orbit. If the position of the sun is s, and the planet is p, then there is always a force acting between them: one on the planet points to the sun, vector t = (s - p) and vice versa. The magnitude of this force is g Ms Mp / (t dot t), where the “point” is the point product, g is the standard acceleration of gravity, and Ms, Mp are the corresponding masses.

If you are making a detailed model where all bodies can stretch all other bodies, then the algorithm must accumulate all paired forces in order to get a single resulting force vector acting on each body (planet or sun). Otherwise, you can agree to the approach, when only the sun pulls on planets and other forces, are considered too small to make a difference.

So the algorithm:

Choose dt, the time step, a small interval. Set initial positions and velocities (for planets, velocity is tangent to desired orbit. Sun has velocity zero.) loop Accumulate all forces on all bodies with current positions. For each body position=p, velocity=v, net resultant force=f, mass=m, update its velocity: v_new = v + f / m dt update position p_new = p + 0.5 * (v + v_new) v = v_new; p = p_new Render end loop 

As already mentioned, Euler is simple, but requires a very small time step in order to obtain even reasonable accuracy. Sometimes you can introduce only a small part of the resistance in the system (multiply the speed by a factor just below 1) to maintain stability, if they otherwise explode.

+5
source

Refer to the project " Moving Stars Around ", there is an old C and an upgraded version of Ruby. (And now the C ++ version?)

A quick tip: Euler’s methods are bad for saving energy. explicit Euler increases energy; implicit Euler reduces energy. Just check it on the phase image of the harmonic oscillator y '' + y = 0.

Use symplectic integrators, the simplest and most well-known is the Leapfrog or Verlet method, which Newton has already used for reasoning about planetary motion.

+10
source

You can try Runge Kutta 4 , but there will still be some “drift” in orbits. Stabilizing the system requires constant total energy of the system, but I'm not sure how to do it. The best method of celestial mechanics is a symplectic integrator .

+2
source

All Articles