Inverse of common ease curves

Alec Jacobson

July 13, 2016

weblog/

Awkwardly I ended up needing the inverse of an ease curve (or S-curve) used in tweening animations. For trigonometric ease curves, this is easy. For example, if your ease filter is:

f = 0.5-cos(x*pi)*0.5;

then the inverse is:

x = acos(-2*(f-0.5))/pi

But if you're using the famous cubic ease curve,

f = 3.*x.^2 - 2.*x.^3

then the relevant inverse is a complex function (involving the i = sqrt(-1)) that produces real values for f in [0,1]:

x = -1./4.*(1-2.*f+2.*(f.^2-f).^(1./2)).^(1./3)-1./4./(1-2.*f+2.*(f.^2-f).^(1./2)).^(1./3)+1./2-1./2.*i.*3.^(1./2).*(1./2.*(1-2.*f+2.*(f.^2-f).^(1./2)).^(1./3)-1./2./(1-2.*f+2.*(f.^2-f).^(1./2)).^(1./3));

I haven't bothered to see if this can be simplified into something tidy. It'd be great to get rid of the i.