<p>Several options are possible:</p>

<p>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. </p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>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</p>

<p>So these can be summarised as:</p>

<ol>
<li>Constant position</li>
<li>Constant velocity</li>
<li>Constant acceleration</li>
<li>Variable acceleration following an inverse square law.</li>
<li>Variable acceleration n-body graviational field.</li>
</ol>

<p>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.</p>

CC BY-SA 3.0
2018-02-03T17:37:06.757Z
2018-02-03T17:37:06.757Z
James K
<p>My question is very similar to <a href="https://astronomy.stackexchange.com/questions/21481/how-can-i-interpolate-ephemerides">this one</a> 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.</p>

<p>For normal vectors or speed I use linear interpolation:</p>

<pre><code>private static float Lerp(float v0, float v1, float t)
{
    return (1 - t) * v0 + t * v1;
}
</code></pre>

<p>But It doesn't work well when I work with orbits</p>

<pre><code>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),
</code></pre>

<p>What function can I use to interpolate them?</p>

CC BY-SA 3.0
2017-12-12T21:06:23.413Z
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
CC BY-SA 3.0
2017-12-12T21:51:47.933Z
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
CC BY-SA 3.0
2017-12-12T23:57:59.900Z
I'd use a cubic spline interpolation.  Much better than linear.
Natsfan
CC BY-SA 3.0
2017-12-13T00:00:57.780Z
If you need more accuracy then you can use a higher order approximation.
A. C. A. C.
CC BY-SA 3.0
2017-12-13T07:26:42.807Z
I know the positions of the planets down to every milisecond (I make all players have the same time so all planet positions are the same for everyone) and I interpolate the position 1 packet in the past.
So once I've got 2 packets I interpolate the position between the 1st and the second, once that interpolation is finished I interpolate between the second and the third, etc...
Gabriel_ES
<orbit>
How can I interpolate 2 orbits
Gabriel_ES
# How can I interpolate 2 orbits

(Asked by: username_0 on 2017-12-12)

My question is very similar to [this one](https://astronomy.stackexchange.com/questions/21481/how-can-i-interpolate-ephemerides) 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?

**Tags:** orbit

> **Comments:**
> **username_1**: 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.  
> **username_0**: 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...  
> **username_2**: I'd use a cubic spline interpolation.  Much better than linear.  
> **username_3**: If you need more accuracy then you can use a higher order approximation.  
> **username_0**: I know the positions of the planets down to every milisecond (I make all players have the same time so all planet positions are the same for everyone) and I interpolate the position 1 packet in the past. So once I've got 2 packets I interpolate the position between the 1st and the second, once that interpolation is finished I interpolate between the second and the third, etc...  

---

## 1 answers

### Answer by username_1 on 2018-02-03. Score: 1

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.


---

