[Math] Easing function, constant velocity then decelerate to zero

functionsinterpolation

I'm trying to write an interpolator for a translate animation, and I'm stuck. The animation passes a single value to the function. This value maps a value representing the elapsed fraction of an animation to a value that represents the interpolated fraction. The value starts at 0 and goes to 1 when the animation completes. So for instance, if I wanted a linear translation (constant velocity) my function would look like:

function(input) {
  return input
}

What I need is for the velocity to remain constant for half the animation, then decelerate rapidly to zero. What this essentially means is that the input values I return must be the same as the output values for half the animation (until 0.5), then the values must increase from 0.5 to 1.0 at a slower rate of change between calls than the input value change between calls.


EDIT (straight from the Android docs):

The following table represents the approximate values that are calculated by example interpolators for an animation that lasts 1000ms:

enter image description here

As the table shows, the LinearInterpolator changes the values at the same speed, .2 for every 200ms that passes. The AccelerateDecelerateInterpolator changes the values faster than LinearInterpolator between 200ms and 600ms and slower between 600ms and 1000ms.


EDIT 2:

I thought I should provide an example of something that works, just not the way I want it to. The function for a decelerate interpolation provided with the Android framework is exactly:

function(input) {
  return (1 - (1 - input) * (1 - input))
}

Best Answer

Let $s(t)$ denote the distance moved at time $t$. Choose some value $h$ with $0 \le h \le 1$. Then the required function is:

$$s(t) = \frac{2t}{1+h} \quad \text{for } 0 \le t \le h $$

$$s(t) = \frac{t^2 - 2t + h^2}{h^2 - 1} \quad \text{for } h \le t \le 1 $$

The first part of the curve (where $0 \le t \le h$) is a straight line, obviously.

The second part (where $h \le t \le 1$) is a piece of parabola. At $t=h$, the line and the parabola join smoothly.

The speed of the particle varies as follows:

From $t=0$ to $t=h$, the speed is constant, $2/(1+h)$.

From $t=h$ to $t=1$, the speed gradually decreases.

At $t=1$, the speed is zero.

You can adjust $h$ to get the behaviour you want. Any value with $0 \le h \le 1$ will work.

If you choose $h=0$, you get the Android function.

If you choose $h=1$, you get purely linear motion.

Here's what the composite curve looks like when we choose $h=0.5$: enter image description here

Related Question