# How can I interpolate 2 orbits

My question is very similar to this one although the answer is not what I was looking for. Basically I'm working in a space game (KSP) and I'm making it multiplayer. The clients send a packet with their orbital parameters at a interval (30 miliseconds by default) but between those packets I want to interpolate and draw an orbit between those 2 packets.

For normal vectors or speed I use linear interpolation:

private static float Lerp(float v0, float v1, float t)
{
return (1 - t) * v0 + t * v1;
}


But It doesn't work well when I work with orbits

var inclination = Lerp(inclination, Target.inclination, lerpPercentage),
var eccentricity = Lerp(eccentricity, Target.eccentricity, lerpPercentage),
var semiMajorAxis = Lerp(semiMajorAxis, Target.semiMajorAxis, lerpPercentage),
var LAN = Lerp(LAN, Target.LAN, lerpPercentage),
var argumentOfPeriapsis = Lerp(argumentOfPeriapsis, Target.argumentOfPeriapsis, lerpPercentage),
var meanAnomalyAtEpoch = Lerp(meanAnomalyAtEpoch, Target.meanAnomalyAtEpoch, lerpPercentage),
var epoch = Lerp(epoch, Target.epoch, lerpPercentage),


What function can I use to interpolate them?

• Why does it not work well. I'd have thought that linear interpolation would be fine for 30ms. The Earth only moves by about 10^{-7} degrees around the sun in 30ms. – James K Dec 12 '17 at 21:06
• Well it really depends, sometimes you can accelerate the time and sometimes packets get lost so there can be a delay of 1 or 2 seconds. So is it correct to use linear interpolation for orbits? I see them jittering but perhaps is because of the game and not the maths... – Gabriel_ES Dec 12 '17 at 21:51
• I'd use a cubic spline interpolation. Much better than linear. – Natsfan Dec 12 '17 at 23:57
• If you need more accuracy then you can use a higher order approximation. – A. C. A. C. Dec 13 '17 at 0:00
• Just curious: is the object around which they orbit fixed? Do you draw this orbit after receiving the 2nd packet? Do you interpolate the position or the orbital elements themselves? – user21 Dec 13 '17 at 1:20

Several options are possible:

Don't interpolate at all. Just assume the planet stays fixed until the next update. The planet Earth moves $10^{-7}$ degrees in 30milliseconds. In the vastness of space that is a rounding error.

Given two objects, their position and velocity and acceleration, and the values of their Keplerian elements at times t0 and t1, you want to estimate their position, velocity and acceleration at any time in between.

You can use simple linear interpolation of their position. This has the advantage of being very quick, but it assumes a constant velocity. Over short time-spans this is a reasonable assumption. For most orbiting bodies this approximation should be accurate enough for differences in time of many minutes, as the changes in velocity are relatively small.

You can assume constant acceleration and interpolate using the SUVAT equation. This does very well if the objects don't move too far. For example it can model the flight of a ball in the Earth's gravitational field very well, giving a parabolic shape. This should give a fairly good approximation of the position over hours, or even days.

You can interpolate the orbital elements, linearly, and solve Kepler's equation to get the position of the body at any given time. For most bodies the Orbital elements change only slowly with time (except for the Anomaly) That is the shape of the orbit stays nearly the same, only the position on the orbit changes. Approximating the orbit of a planet by interpolation of its elements should give a good approximation for several hundred years of orbital time. However the process of solving the equation is slow.

Finally you can numerically integrate the n-body problem for the solar system. Depending on the time step you choose this can be accurate for an indefinite amount of time

So these can be summarised as:

1. Constant position
2. Constant velocity
3. Constant acceleration
4. Variable acceleration following an inverse square law.
5. Variable acceleration n-body graviational field.

For a game engine, speed is good. If the gaps in time are on the order of milliseconds (of real time) then simply not interpolating should be undetectable.