# The mathematics behind interpolations

**URL:** <https://forums.synfig.org/t/the-mathematics-behind-interpolations/11977>\
**Category:** Documentation\
**Created:** [March 26, 2021, 11:50am UTC](https://forums.synfig.org/t/the-mathematics-behind-interpolations/11977 "2021-03-26T11:50:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobo\_the\_King](https://forums.synfig.org/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@Bobo\_the\_King](https://forums.synfig.org/u/Bobo_the_King)\
**Post date:** [March 26, 2021, 11:50am UTC](https://forums.synfig.org/t/the-mathematics-behind-interpolations/11977/1 "2021-03-26T11:50:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rodolforg](https://forums.synfig.org/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@rodolforg](https://forums.synfig.org/u/rodolforg)\
**Post date:** [March 27, 2021, 7:24am UTC](https://forums.synfig.org/t/the-mathematics-behind-interpolations/11977/2 "2021-03-27T07:24:41Z")

</div>

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

> <https://github.com/synfig/synfig/blob/1ffe5c321e0c8c6a13168e6a4f65025f4fbd0537/synfig-core/src/synfig/valuenodes/valuenode_animatedinterface.cpp#L397>

---

<div class="post-metadata">

**Author:** ![Bobo\_the\_King](https://forums.synfig.org/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@Bobo\_the\_King](https://forums.synfig.org/u/Bobo_the_King)\
**Post date:** [March 27, 2021, 8:22am UTC](https://forums.synfig.org/t/the-mathematics-behind-interpolations/11977/3 "2021-03-27T08:22:31Z")

</div>

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.
