2
$\begingroup$

I'm coding a game, and a fundamental mechanic is celestial bodies moving in elliptical, Keplerian orbits around a single gravitational point in a planetary system (not our solar system). The bodies in this system all have their orbital elements and masses defined, and those orbital elements do not ever change throughout the game (except true anomaly, of course).

I'm trying to solve a problem, and I don't know how to approach it in a way that will work.

The problem is:

GIVEN (as function inputs)
Orbiting mass "m" (kg, a planet)
Orbited mass "M" (kg, a star)
Semimajor axis (in AU)
Eccentricity (0 < e < 1)
Inclination (rads or degrees)
Longitude of ascending node (rads or degrees)
Argument of periapsis (rads or degrees)
True anomaly (current position of planet in orbit)
Delta Time (seconds, minutes, hours, days, months, etc)

OUTPUT: Position (in xyz coords with gravitational point at origin 0,0,0) How can I find the position of the planet after time t?

THE DIFFICULTY IS...
I already can calculate the distance vector and instantaneous velocity of the planet (thanks to http://orbitsimulator.com/formulas !!!), but that only tells me where the planet will be after 1 second and...
delta time needs to be any value from 1 second to 100+ days!

The only solution I can think of involves running that "update body position each second" a bazillion times (ie if you want to see where it will be in 1 minute, run the "find velocity of orbiting body" function 60 times, updating the position each time), and then showing the final result, which isn't practical when you want to see where it will be in a month or more (and not practical when updating the positions of different bodies after different time deltas). Considering the velocity of the body changes in an elliptical orbit from moment to moment, how can this problem be solved efficiently for arbitrarily long time deltas?

I know Elite: Frontier got something like this working way back when, but I have no idea how...I've been reading up as much as I can find for the past month! ...mostly from Orbital Mechanics for Engineering Students by Howard Curtis, and I struggle considerably with understanding calculus equations.

Much appreciation for all you celestial mechanics savants and any insight or solutions you may have to share!

$\endgroup$
8
  • 3
    $\begingroup$ At the risk of stating the (hopefully) obvious: have you tried solving using Kepler's equation? If so, why did that not work? $\endgroup$ Commented May 8, 2023 at 14:32
  • $\begingroup$ You're describing a software problem, not an orbital mechanics problem, and you seem to be overestimating the complexity. Your "bazillion" is less than 9 million which is a small number these days. Worst case you could precalculate millions of positions versus time and store them then just do a lookup. Can't imagine a game where time increments from seconds to hundreds of days would matter. $\endgroup$
    – stretch
    Commented May 8, 2023 at 15:26
  • 1
    $\begingroup$ You can easily invert Kepler's equation using Newton's method. It converges quickly, unless the eccentricity is very close to 1. Here's a short demo in Python. $\endgroup$
    – PM 2Ring
    Commented May 8, 2023 at 18:04
  • $\begingroup$ sagecell.sagemath.org/… $\endgroup$
    – PM 2Ring
    Commented May 8, 2023 at 18:05
  • 1
    $\begingroup$ See also "How to get true anomaly from time?" $\endgroup$
    – Sten
    Commented May 9, 2023 at 9:34

0

You must log in to answer this question.