Jump to content

Calculate the position of a planet at a given time


yaur

Recommended Posts

I'm trying to work out how to figure out the position of a planet given a time. I've googled quite a bit and so far the best I've come up with is http://www.stjarnhimlen.se/comp/ppcomp.html this has good math but requires an iterative method to work out "true anamoly" for a given time. This is obviously not what KSP does or warping at x10000 wouldn't be possible. Since my end product is tol that can answer questions like "when will eve block the view of Duna from Kerbin" I am hoping someone here knows how KSP calculates position in orbit/true anomaly.

Link to comment
Share on other sites

KSP uses patched conic approximation while real space like in the link uses n-body calculation, as far as I know KSP uses patched conic because they doesn't need to be iterative, but it could use an equation (?)

The others might know more about this than me

Link to comment
Share on other sites

I'm assuming you only want/need this for elliptical orbits, right?

EDIT:

If so, you'll want to use Kepler's equation for elliptical orbits:

M(t) = E - e*sin*(E)

M(t) is the mean anomaly of the orbit:

M(t) = sqrt(mu / a^3) * (t - tau)

where mu is the gravitational parameter of the sun, a is the planet's semi-major axis, and (t - tau) is the time that has elapsed since the planet's last passage of periapse.

E is called the Elliptical Anomaly, and can be found as a function of true anomaly nu (the angle traversed by the planet since last passage of periapse as viewed by the sun)

tan(nu/2) = sqrt((1+e)/(1-e)) * tan(E/2)

and e is the eccentricity of the planet's orbit.

If you know mu, a, e, and nu (which can be calculated from the conic section equation), you can calculate the time elapsed since last periapse. Using a root finding algorithm like Newton's method (*very* fast algorithm - requires one or two iterations usually - if you set E = M for the initial guess if e is small or E = pi if e > 0.8) to find E given (t - tau) and back-solve for nu.

Hope that helps!

EDIT 2: Make sure you keep E in radians!

Edited by tntristan12
Link to comment
Share on other sites

Correct, only for elliptical. I was under the impression that patched conics wouldn't really matter here other than the lack of perturbations in orbits.

What's the problem here? You can compute mean anomaly. You can compute true anomaly from that. The orbit can be any conic section, it doesn't matter. (You do have to be careful with periods of hyperbolic orbits, but if you are comfortable with complex math, equations generalize to this case as well.)

The difficulty is with real planets/moons only, because their orbital elements evolve over time. In KSP, orbital elements are fixed, so equations are very simple.

Link to comment
Share on other sites

this has good math but requires an iterative method to work out "true anamoly" for a given time. This is obviously not what KSP does or warping at x10000 wouldn't be possible.
Wrong assumption. Iterative methods are the only thing you can use to get the position in a given orbit at a specific time. So that is what KSP does. For most orbits, it does not require too many iterations. Plus, for high warp speeds, solving the equations with the desired precision that way is much faster than solving the equations of motion numerically brute force style.

There is a way to avoid iteratively solving for the true anomaly from the mean anomaly: Ask a different question :) Not "Where is the planet at time T?" but "When will the planet be at position X that I know is on the orbit?". That can be solved "exactly", you need to calculate the mean from the true anomaly then.

Quotes around "exactly" because you still need trigonometry and square roots. Guess how those have to be calculated in the end.

Link to comment
Share on other sites

I'm trying to work out how to figure out the position of a planet given a time. I've googled quite a bit and so far the best I've come up with is http://www.stjarnhimlen.se/comp/ppcomp.html this has good math but requires an iterative method to work out "true anamoly" for a given time. This is obviously not what KSP does or warping at x10000 wouldn't be possible. Since my end product is tol that can answer questions like "when will eve block the view of Duna from Kerbin" I am hoping someone here knows how KSP calculates position in orbit/true anomaly.

Don't worry about the iteration for eccentric anomaly, it should converge very quickly. At least in my experience (using this sort of formula -- Kepler's equation -- for the bodies in stock KSP), if it hasn't converged (difference of less than ~ 10-12 between iterations, say) within half a dozen iterations, something is wrong. If your given time can get large compared to the period of the orbit you're computing, do make sure to bring the mean anomaly back into the range 0 .. 2*pi. A large mean anomaly will hurt convergence.

I'm pretty sure KSP does something very much like this. Time warping is not an issue -- since everything in the game follows conic sections, the game needs to do this every frame for every vessel and body in the game. It doesn't matter if the time difference between frames is 1/60 second or thousands of seconds, the effort required is the same. And any modern computer should be able to do hundreds of thousands of these calculations in a second, without even getting into multithreading, etc.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...