TITLE: Is there an explicit form for cubic Bézier curves?
QUESTION [41 upvotes]: (See edits at the bottom) 
I'm trying to use Bézier curves as an animation tool. Here's an image of what I'm talking about:

Basically, the value axis can represent anything that can be animated (position, scaling, color, basically any numerical value). The Bézier curve is used to control the speed at which the value is changing as well as it start and ending value and time. In this graphic, the animated value would slowly accelerate to a constant speed, then decelerate and stop.
The problem is, that Bézier curve is defined with parametric equations.
$f_x(t):=(1-t)^3p_{1x} + 3t(1-t)^2p_{2x} + 3t^2(1-t)p_{3x} + t^3p_{4x}$
$f_y(t):=(1-t)^3p_{1y} + 3t(1-t)^2p_{2y} + 3t^2(1-t)p_{3y} + t^3p_{4y}$
What I need is a representation of that same Bézier curve, but defined as value = g(time), that is, y = g(x).
I've tried solving for t in the x equation and substituting it in the y equation, but that 3rd degree is giving me some difficulty.
I also tried integrating the derivative of the Bézier curve (dy/dx) with respect to t, but no luck.
Any ideas?
Note : "Undefined" situations are avoided by preventing the tangent control points from going outside the hull horizontally, preventing any overlap in the time axis.
EDIT :
I have found two possible solutions. One uses Decasteljau's algorithm to approximate the $s$ parameter from the $t$ parameter, $s$ being the parameter of the parametric curve and $t$ being the time parameter. Here (at the bottom).
The other, from what I can understand of it, recreates a third degree polynomial equation matching the curve by solving a system of linear equation. Here. I understand the idea, but I'm not sure of the implementation. Any help?

REPLY [2 votes]: I Probably Shouldn't Do This
My previous answer made clear that I think your question was the wrong question. But on principle, I can't leave it at that; I will answer the question anyway...
If you're really determined to draw shapes with your familiar Bezier tools, and to use one coordinate of a resulting curve as an easing value, I recommend that you use one of the following methods:
Numerically solve the polynomial P(t) - x = 0 to find t, using an end point as a 'first guess'.
You already know a solution at each end of the curve. Either of those is a good first guess for the next or previous value, which is a good first guess for the next value you want, and so on. That means you can use a numerical solver very quickly and accurately, and usually only finding one root.
You hinted at a similar solution, but you didn't seem very happy with it, calling it 'a bit hacky'. Here I mean to get you thinking more clearly about it, because it needn't bit at all hacky, and can be both quite fast as well as the most accurate.
Wikipedia's page on root finding algorithms has many possibilities to suggest, and you needn't even bother assessing their relative merits much; go with whatever you find easy to implement. Having a first guess to hand means lots of methods work very, very well in terms of both speed and accuracy.
For values of x that correspond to multiple different values of t, the value of t that is closest to your previous value will be found, and that seems desirable. The only question then is how to behave when the value you've been tracking vanishes.
Consider drawing an upright S shape on the graph in your example. Scanning from left to right, we start with only one solution, but then two more appear in a manner reminiscent of a particle-antiparticle creation. What is the definition of the behaviour you desire, in such cases?
At this stage most root finding algorithms will continue to return the t value corresponding to the bottom-most root. But when the original root and the middle root collide, they annihilate, again in a way reminiscent of particles and antiparticles.
What happens there depends a bit more on your choice of root solver. In most cases there will be two consequences. Usually, the root will simply jump to the top of the S, and take slightly more calculation time on that step. (Tracing back to the left will then stay on the top of the S.) For some choices of root finder, you could run into a bigger problem here, like the root finder no longer converging on any root, because the initial guess was too far away.
If you actually want to know about all the possible roots, that takes a bit more work. By removing a factor of (t - root) from the polynomial P(t) - x you will get a lower order expression, making it successively easier to find subsequent roots. But the division is difficult, and the accuracy of each subsequent root tends to be much worse than the last one. I would use these subsequent calculations of roots as first guesses for a further numerical iteration.
If you think multiple roots won't affect you for the curves you're likely to draw, because you're drawing single-valued functions, beware. Just because there is a single valid solution in the curve segment you've drawn, doesn't mean the root finder won't discover other solutions from outside it. The fact that the equation potentially has three roots makes your calculation harder even if only one is real, or only one is in the valid t domain.
And Here's Another Way
First, notice that the quadratic Bezier is a much easier case. You can get both solutions of t for every value of x from the quadratic formula, and making a consistent choice of root is easy.
So how closely can you approximate one cubic Bezier with many quadratic Beziers?
If using this method, remember that while any one subdivision can now give a maximum of two roots, the entire curve could have a total of three.
But HONESTLY You're Better Off With These!
Calculating polynomial expressions is easy, 'forward' mathematics; rooting finding is difficult, 'backwards' mathematics. Go forwards; make it easy for you AND for the computer; don't calculate roots for such a basic component of animation as easing.
As suggested by bubba:
Cubic easing from 0 to 1, over t = 0 to t = 1
ease = 3t^2 − 2t^3

Cubic easing from -1 to 1, over t = -1 to t = 1
ease = (3t - t^3)/2

These trig solutions also look nice. Trig is quicker if you calculate each sin(t) from the cos and sin of the previous t with some linear algebra; I advise doing so in any inside loop of an animation
Harmonic easing from 0 to 1, over t = 0 to t = 1:
ease = (1 + sin(pi.(2t - 1))) / 2

Harmonic easing from -1 to 1, over t = -1 to t = 1:
ease = sin(pi.t)

You can still have an intuitive, graphical interface for designing lots of these functions.
If control points are horizontally fixed, your graph would actually provide a nice way to design a 1D Bezier of any order at all, with the independent variable represented on the horizontal axis.
With that one 'restriction' it would be a very intuitive interface for setting positions and velocities. It would be nice to extend that into an interface for providing velocities and accelerations, and then accelerations and jerks, and then jerks and jounces. Each new graph can provide positions from the previous graph, and just needs the gradients to be added.
And nobody could criticise that for a lack of 'expressiveness'!