nbody approximation 
keebus  Date: Saturday, 31.03.2012, 19:16  Message # 1 
Observer
Group: Newbies
Italy
Messages: 6
Status: Offline
 Hello all,
I was wondering, can you point me to the solution to the nbody problem used by SpaceEngine? I guess an exact calculation is not made as (as far as I know) there is no known solution or it is too computationally expensive.
I'd be glad if you could give me some hints. I was (perhaps a little naively) considering approximating it with a collection of 2body approximation. I know it would be a potentially inexact solution, but I'm only interested on plausible, not too incorrect solutions.
Thank you very much.
p.s.: I'd be glad if you could also point me to a way to calculate bodies coordinates in any, absolute time t, giving we know all body parametes (initial position and velocity, as well as "the entity orbiting around to").


 

SpaceEngineer  Date: Sunday, 01.04.2012, 01:58  Message # 2 
Author of Space Engine
Group: Administrators
Russian Federation
Messages: 4800
Status: Offline
 SE does not use Nbody simulation  it is computationally expensive and impossible due to adjustable timerate. This can be compared to avi file with no keyframes: if you rewind player to some point, you should wait until codec builds all the frames from the beginning of the movie to your point. So if I would use Nbody simulation, I should define initial coordinates and velocities for every body in system, for 1 a.d. for example, and then run the simulation until time reaches the player's current time. And I should note reduced accuracy, because this may lead to a different result for different players. Such calculation may take hours depending on PC speed.
Because of that, in SE I use analytic solution for twobody problem  this is wellknown Kepler equations. I can emulate only stable periodic orbits, but almost all systems in universe are stable. These solution do "calculate bodies coordinates in any, absolute time t, giving we know all body parametes (initial position and velocity, as well as 'the entity orbiting around to')." So no expensive calculations performed. The accuracy is perfect for game purposes.
However, for spaceships I should use the first approach, so time traveling becomes almost impossible. It is good that in a multiplayer game time travel will be already disabled.
*


 

keebus  Date: Sunday, 01.04.2012, 10:52  Message # 3 
Observer
Group: Newbies
Italy
Messages: 6
Status: Offline
 Hello SpaceEngineer,
thank you for your quick answer. I'm glad to see I've come to the same solutiouon you found. Just one little note: you said you naturally keep a reference to the object you're orbiting about. This is pretty intuitive, what I'm considering, is a multiple stars system or a planet with several moons where for example one of them has enough mass to influence it's primary planet orbit.
So what I've finally come to is the following: suppose we're generating a planet with its moons. See if one of the moons has "enough" mass, and if so, convert the pair planethigh mass moon to a 2body simulation (thus calculating the barycenter) and let other moons orbit around this barycenter.
The same would happen for a triple star system: I would take the two most massive stars, couple them into a 2body sim, and let lightest start orbit around one of the two or around the barycenter of the previous 2body sim.
Does it sound correct?


 

SpaceEngineer  Date: Sunday, 01.04.2012, 11:43  Message # 4 
Author of Space Engine
Group: Administrators
Russian Federation
Messages: 4800
Status: Offline
 Yes, I use the same in SE. If senond body is massive enough, the barycenter is calculated (with summary mass of these two bodies), and two bodies run start orbiting it (with correctly computed orbital elements  the same peroids, inclinations, ascenging nodes, with argument of pericenter differs by 180°, and the semimajor axes proportionally to their mass ratio). It is possible to third body to have stablo orbit in this system  very close to any of these two bodies, or orbiting the barycenter far enough (35 times farther than second body's semimajor axis).


 

keebus  Date: Sunday, 01.04.2012, 12:17  Message # 5 
Observer
Group: Newbies
Italy
Messages: 6
Status: Offline
 Oh thank you very much. As one last effort, I'm struggling finding some good reference on how to calculate these orbital characteristiccs, the ones you just mentioned: period, inclination, ascending node, pericenter and most importantly semimajor axis. Can you point me to some good reference?
Thank you very much for your help.


 

SpaceEngineer  Date: Sunday, 01.04.2012, 12:37  Message # 6 
Author of Space Engine
Group: Administrators
Russian Federation
Messages: 4800
Status: Offline
 I do not use any reference. Maybe because I am astronomer, and know all it from student days All you need is Kepler's laws and definition of orbital elements. I generate all angular elements randomly, but taking into account complanarness of orbits. Semimajor axis I generate using geometric progression with small random offset, then calculate period using sun mass and Kepler's laws. In render stage, I calculate position of a planet relative to its parent using Kepler's equation and rotation matrix, calculated from angular elements. Coordinates relative system's center is obtained by recursуe through system's heirarchy.


 

keebus  Date: Sunday, 01.04.2012, 23:59  Message # 7 
Observer
Group: Newbies
Italy
Messages: 6
Status: Offline
 I've been reading all the pages I found on Wikipedia, including the ones you pointed me to.
I'm still missing the final point though, that is, given the 6 (constant) paramaters that exactly describe an elliptic orbit, what is the final function r(t) (r is the displacement vector from the sun to the planet).
Could you kindly help me out?


 

SpaceEngineer  Date: Monday, 02.04.2012, 01:10  Message # 8 
Author of Space Engine
Group: Administrators
Russian Federation
Messages: 4800
Status: Offline
 You can spy on it in the Celestia source code I use my own function, but it's a pretty match with Celestia's (obviously).
*


 

keebus  Date: Monday, 02.04.2012, 10:43  Message # 9 
Observer
Group: Newbies
Italy
Messages: 6
Status: Offline
 Oh thank you! This is a very neat idea Btw I think I'm getting close to it I'll write back what I realize just to get an astronomer "OK" (I'm a computer engineer).


 

keebus  Date: Monday, 02.04.2012, 12:41  Message # 10 
Observer
Group: Newbies
Italy
Messages: 6
Status: Offline
 Thanks a lot! It worked!
Btw I'm happy to see that I was actually correct. The whole problem reduces to finding the eccentric anomaly some way. My doubts were like "Do I REALLY have to compute it numerically? Isn't there any maybe inexhact but fast way to compute E?"
As I can see, numerical, iterative procedures are used, so alright, I feel fine now
Thanks a lot for your huge help. So basically, now that I have a body orbiting around a fixed point, to have a pair of bodies orbiting around a barycenter all I have to do is give them absolutely same 6 parameters only changing the Mean Anomaly (i consider epoch = 0) out of phase of 180°. A final confirmation?


 

SpaceEngineer  Date: Monday, 02.04.2012, 21:01  Message # 11 
Author of Space Engine
Group: Administrators
Russian Federation
Messages: 4800
Status: Offline
 Quote (keebus) "Do I REALLY have to compute it numerically? Isn't there any maybe inexhact but fast way to compute E?" Kepler's equation does not have an analytical solution, so numerical iterations are the only way to solve it. However, it's very fast  you need just 35 iterations for almost a circular orbit and 1020 iterations for orbits with e < 0.2. Some advanced iteration schemes are used for high eccentic orbits.
Quote (keebus) So basically, now that I have a body orbiting around a fixed point, to have a pair of bodies orbiting around a barycenter all I have to do is give them absolutely same 6 parameters only changing the Mean Anomaly (i consider epoch = 0) out of phase of 180°. A final confirmation? Confirmed Just do a visualisation and look at behaviour of a planets.
*


 