I'm a senior software developer but my math lessons are a bit rusty. I know the name of what I want, but not anymore how to compute it ;)

I've found (by myself with Grapher.app) a simple easing function (for transitions), that's a bijection from $[0,1]$ to $[0,1]$:

$$ f(x) = \frac{27}{4} \cdot \left( \left( \frac{2x}3 \right) ^2 - \left( \frac{2x}3 \right) ^3 \right) $$

Edit: in fact, after simplifying, it's as simple as:

$$ f(x) = 3 x^2 - 2 x^3 $$

The derivatives at $0$ and $1$ are both zero, so it's a perfect ease-in-out function that's easy to compute.

In order to start my transitions from anywhere between $0$ and $1$, I need $f^{-1}$, the inverse of this function, but I'm completely lost as to where to start... Would someone shed some light on my oh-gosh-it-was-so-long-ago math course?

  • $\begingroup$ normal form: y=function of x, inverse: x=function of y $\endgroup$ – Bob Jan 31 '13 at 19:52
  • 1
    $\begingroup$ It's simpler and easier to understand if you write $f(x)=3x^2-2x^3$. $\endgroup$ – user1551 Jan 31 '13 at 19:54
  • $\begingroup$ Oh. My. Didn't even think of simplifying it. When I told you I'm rusty... $\endgroup$ – Cyrille Jan 31 '13 at 20:48

Take your equation $3 x^2 - 2 x^3 = y$, substitute $x = X + 1/2$, multiply by $2$ and expand to get $-4X^3 + 3 X = 2 y - 1$. Now note that $\sin(3t) = - 4 \sin(t)^3 + 3 \sin(t)$. Thus a solution is $X = \sin(t)$ where $\sin(3t) = 2y-1$, i.e. $$ x = \sin\left(\frac{\arcsin(2y-1)}{3}\right) + 1/2 $$

Note that $0 \le x \le 1$ when $0 \le y \le 1$.

  • $\begingroup$ Wait wait wait... sinuses? $\endgroup$ – Cyrille Jan 31 '13 at 20:51
  • $\begingroup$ Okay, after re-reading it like ten times, it makes sense. $\endgroup$ – Cyrille Jan 31 '13 at 21:02
  • 1
    $\begingroup$ What I've always wondered (and that's where the beauty of maths comes from) is: where did you take the "substitute x = X + 1/2" from? I mean, did you just have to say "shazam" to find this? $\endgroup$ – Cyrille Jan 31 '13 at 21:11
  • $\begingroup$ Take $x = X + a$ and see what $a$ has to be to eliminate the $X^2$ term. $\endgroup$ – Robert Israel Jan 31 '13 at 23:35

The inverse function $g(y)$ satisfies $f[g(y)] = y$. In this case:

$$\frac{27}{4} \cdot \left( \left( \frac{2g(y)}3 \right) ^2 - \left( \frac{2g(y)}3 \right) ^3 \right) = y$$

Solve for $g(y)$ algebraically. Might be tough because it's a cubic, but it is possible.


You can ask to wolfram alpha:

1/2 (1+1/(1-2 x+2 sqrt(-x+x^2))^(1/3)+(1-2 x+2 sqrt(-x+x^2))^(1/3))

Or either you could implement the bisection method to solve $f(x) = y$. One should check, but it is possible that in this case the bisection method is faster than using the explicit formula for inverse.

  • $\begingroup$ Didn't even knew you could ask this to Wolfram. Thanks! $\endgroup$ – Cyrille Jan 31 '13 at 21:05
  • $\begingroup$ But notice that when $x \in (0,1)$, you're taking the square root of a negative number. This is no accident: see en.wikipedia.org/wiki/Casus_irreducibilis $\endgroup$ – Robert Israel Jan 31 '13 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.