And Now, A Two-Point Cubic Spline
The simple quadratic spline discussed my previous post seems to be sufficient for interpolating particle positions between two GADGET-2 snapshots for the purposes of making animations, but it's also possible to use a cubic spline for the task. The advantages of using a cubic spline are (1) it can be more accurate—especially in cases where the acceleration changes sign once between snapshots, and (2) the derivatives at the end-points of the spline match the derivatives specified in the input data. In the case of the quadratic spline, if the acceleration (second derivative) changes sign even once during the interval, the interpolation is poor and the derivative of the spline at the end points is not guaranteed to match the specified value. Thus, in the case of the quadratic spline, the derivative is generally discontinuous when moving from one interval to another. This doesn't matter too much when making animations with reasonably small intervals, but it would be important for certain other situations. The disadvantage of the cubic spline is that it adds complexity.
Cubic spline interpolation seems to be quite popular. Derivations of the general method can be found in most textbooks on numerical methods. I'll just discuss the specific result that's useful for my application—the cubic spline in terms of the end-point positions and velocities. To derive the result, we just have to slightly modify the derivation given in the previous post. We add a jerk term (third derivative of the position with respect to time) to the third and fourth Taylor expansions,
and solve the system of equations for . There are, of course, several ways of doing this. I'll skip the details and show the end result. I defined
In terms of these definitions,
This can be written more compactly as
As an example, the cubic function generated by this technique when given values corresponding to at and is
In the plot below, is the blue curve and is the dotted black curve.