 # The mathematics behind interpolations

I’d add this to the wiki myself, but everything seems to be locked. I want to include information on each of the interpolations, with special focus on the relevant differential equations. Here’s what I have so far:

Let t represent the frame number and y the value being animated (interpolated). Additionally, let t_0 be the initial frame and t_f be the final frame with y_0 and y_f the respective known values (for the sake of writing boundary conditions). Each of the interpolations can be represented as a function or a differential equation with boundary conditions. Both the out- and in- interpolations must be specified for the function/DE to be uniquely defined.

Constant-(any) or (any)-constant:
Function: y(t) = y(t_0) (t < t_f)
y(t) = y(t_f) (t >= t_f)

Linear-linear:
DE: y’’ = 0
BCs: y(t_0) = y_0
y(t_f) = y_f
Function: (y - y_0) = (y_f - y_0)/(t_f - t_0)*(t - t_0)

Ease in/out-ease in/out:
DE: y’’’’ = 0
BCs: y(t_0) = y_0
y’(t_0) = 0
y(t_f) = y_f
y’(t_f) = 0
Function: y = A*t^3 + B*t^2 + C*t + D (Subject to BCs)

Ease in/out-linear:
DE: y’’’’ = 0
BCs: y(t_0) = y_0
y’(t_0) = 0
y(t_f) = y_f
y’(t_f) = (y_f - y_0)/(t_f - t_0)

(This last BC indicates a “problem” with the ease in/out-linear spline. We expect that as t approaches t_f, the linear interpolation will dominate and y’ will be constant, i.e., y’’ = 0. Instead, if you graph this function, you’ll find that y’ overshoots its maximum/minimum. I suggest changing the second BC to y’’(t_f) = 0, but admittedly this will muck up a lot of legacy definitions. Maybe introduce a “new linear” waypoint, with the old linear waypoint to be phased out?)

Clamped-clamped (no waypoint after):
(Same as linear.)

Clamped-clamped-clamped:
Functions: y_a(t) = A_1*t^3 + B_1*t^2 + C_1*t + D_1 (first interval)
y_b(t) = A_2*t^3 + B_2*t^2 + C_2*t + D_2 (second interval)
BCs: y_a(t_0) = y_0
y_a(t_1) = y_1
y_b(t_1) = y_1
y_b(t_2) = y_2 (The previous four BCs all demand the function take the appropriate values at the three specified points.)
y_a’(t_1) = y_b’(t_1) (Continuity of first derivative at t_1.)
y_a’(t_0) = (y_1-y_0)/(t_1-t_0)
y_b’(t_2) = (y_2-y_1)/(t_2-t_1) (This BC and the previous one are both problematic for the same reason I indicated for the linear interpolation.)
(Possible last BC: y_b’’(t_1)-y_a’’(t_1) = g(t_0, t_1, t_2, y_0, y_1, y_2), where g is not an elementary function. I’ve been able to show that the difference between the second derivatives at the intermediate point varies somehow and this would fill the gap in the boundary conditions. I’ve even been able to determine that g appears to take rational values for certain inputs, such as t_0=0, y_0=0, t_1=20, y_1=0, t_2=120, y_2=1 implies g=0.0004. Another rational value occurs at t_0=0, y_0=0, t_1=100, y_1=0, t_2=120, y_2=1, implying g=0.0100003. These “rational” values may be subject to rounding errors and are just speculation.)

(Nothing yet for TCB. Give me time to research it or help me out with your own research.)

Currently, I’m investigating these by creating a text layer, converting the text to a real string and animating the input real value. I then enclose it in a group layer and put a duplicate layer above it, linking the time offset (and spatial offset) to the duplicate layer’s ValueBase node, producing a list of numbers. I enter the numbers into Excel, compute (or rather, estimate) the derivatives manually, and look for any patterns. Any help would be appreciated! And if possible, add these to the wiki, too.

If you can read C++ (and Synfig beast), here is the starting point of the related code location:

Thanks for this! I have a bit of programming background but nothing really in C++. I’ll keep looking through this and see if I can decipher it.