Quadratic Spline Interpolation
While animating my first GADGET-2 galaxy mergers, I discovered that setting the frame rate to the common value of 25 frames per second resulted in movies that were too fast. The complexity of the merger process couldn't be appreciated--even though the snapshot interval was quite small (0.005 simulation time units). I had to interpolate the GADGET-2 snapshots in order to produce intermediate frames that could be used to slow the animation down. Linear interpolation didn't work well enough to meet my standards, so I looked for an efficient quadratic interpolation scheme. I wanted to perform a quadratic interpolation using only two snapshots at a time (a quadratic interpolation using two snapshots is possible in this case because each snapshot contains particle position and velocity information). The first thing that came to mind was simply using the familiar expression

to take a half-step forward from the first snapshot and a half step backward from the second snapshot and then average the two results together to estimate the likely position of each particle in the snapshot like this:

Where
is the time interval between snapshots
and
,
is the position of a particle at time
after snapshot
,
,
,
, and
are the positions and velocities of the particle at snapshot
and snapshot
. This method is slightly better than linear interpolation, but not as good as using a quadratic spline. I tested it out and the results were disappointing. I searched my computational physics and numerical analysis textbooks and searched the web, but I couldn't find what I was looking for, so I derived the method myself. My final result was
![\displaystyle\mathbf{r}(t)=\frac{1}{\delta t}\left[\mathbf{r}_0(t_1-t)-\mathbf{r}_1(t_0-t)\right]+\frac{1}{2\delta t}\left(\mathbf{v}_1-\mathbf{v}_0\right)(t_1-t)(t_0-t)](http://www.idius.net/wp-content/plugins/latex/cache/tex_f6b4e819330641cf0ab13a1bd0ffed24.gif)
This is very closely related to a quadratic Bézier curve. The derivation follows:
The Taylor expansion of a function
about the point
is

It is possible to approximate the value of the function at
using a Taylor expansion by swapping
with
in the expansion above and truncating the series:

Writing expansions for
,
,
and
,




Eliminating
using the third and fourth equations:

The first two equations then become
![\mathbf{r}_{0}\approx\mathbf{r}(t)+\frac{1}{2}(t_{0}-t)[\mathbf{v}_{0}+\mathbf{v}(t)]](http://www.idius.net/wp-content/plugins/latex/cache/tex_864a7b631adfbd06b5d801a51c4217db.gif)
![\mathbf{r}_{1}\approx\mathbf{r}(t)+\frac{1}{2}(t_{1}-t)[\mathbf{v}_{1}+\mathbf{v}(t)]](http://www.idius.net/wp-content/plugins/latex/cache/tex_18c7dd60c744f80b4cbf03ee94a0e9a8.gif)
Now we eliminate
between the two equations

Solving for
and defining
yields the result stated above.
This is a decent approximation for the motion of each particle between snapshots. In fact, it's a pretty good approximation for any function with specified end point values and first derivatives as long as the sign of the second derivative doesn't change during the interval.
For demonstration purposes, the blue curve below is
. The black dashed curve is the interpolating parabola generated by the expression derived above for endpoints at
and
. The red dashed curve is the interpolating parabola for endpoints at
and 
Tags: animation, interpolation

