Over the past couple of weeks I've been trying to simulate orbits in a solar system simulation I am making as part of a University module. To cut things short, my simulation is written in C++ using the Ogre3D rendering engine. I have attempted to implement orbits using Newton's law of universal gravitation which made my planet head towards the sun in a straight line, pass through the sun and then come back to its starting position. I also tried the steps from 'Position as a function of time' section of this wikipedia article, but that did not work for me either.
I am driving the simulation with a simple Euler integration method. If anyone has any experience with this kind of simulation, or just generally knows a lot about these physics laws then any help or pointing me in the right direction would be greatly appreciated.
The orbit formula, r = (h2/μ)/(1 + e cos θ), gives the position of body m2 in its orbit around m1 as a function of the true anomaly. For many practical reasons we need to be able to determine the position of m2 as a function of time.
FACT 1. The station travels from west to east on an orbital inclination of 51.6 degrees. Each orbit takes 90-93 minutes, depending on the exact altitude of the ISS.
Solving for the orbit velocity, we have vorbit=47km/s v orbit = 47 km/s . Finally, we can determine the period of the orbit directly from T=2πr/vorbit T = 2 π r / v orbit , to find that the period is T=1.6×1018s T = 1.6 × 10 18 s , about 50 billion years.
Consult the project "Moving stars around", there is an old C and a modernized Ruby version. (And now a C++ version?)
Short advice: Eulers methods are bad for energy conservation. explicit Euler increases energy, implicit Euler reduces energy. Just check it on the phase space picture of the harmonic oscillator y''+y=0.
Use symplectic integrators, the most simple and famous is the Leapfrog or Verlet method that already Newton used to reason about planetary movement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With