Hacker News new | ask | show | jobs
by saucerful 5403 days ago
Yes, if you want a constant speed you need to re-parametrize by arclength, which is straightforward for quadratic (or, more generally, polynomial) curves as there is a simple closed expression for their length.
2 comments

You are correct about the re-parametrization. A closed expression for arc-length is news to me however. Do you have a citation?
There's a closed-form expression for the arc length of a quadratic Bezier segment. Maybe that's what he had in mind. The integrand is sqrt(x'(t)^2 + y'(t)) dt, where x(t) and y(t) are quadratic in t and hence x'(t) and y'(t) are linear, so it just works out to the square root of a quadratic polynomial. With the quadratic formula to the rescue and a clever substitution, you get this closed form:

http://www.wolframalpha.com/input/?i=integrate+sqrt%28a+x^2+...

This page documents the derivation in more detail:

http://segfaultlabs.com/docs/quadratic-bezier-curve-length

But should you use this for reparameterization? One great thing about calculating arc length by numerical quadrature is that you get all the intermediate arc lengths for the initial segments of the curve for free as intermediate results. Those are exactly what you need for reparameterization, and it works for polynomial and rational curves of any degree whatsoever, not only quadratics.

By contrast, there's no way you could find a closed-form expression for the _inverse_ of that arc length function for reparameterization, so you'd still need to do the same old iterative inversion thing of tabulating it at a bunch of points and then inverting the table and lerping between the gaps. The incremental evaluation required for that is a much better fit for numerical quadrature. If you have to do one, you might as well do both.

But those tend not to have a zero derivative at the vertices, no? Which would cause other animation problems, if you try to link two curves together.
Yes, a quadratic Bezier is only piecewise differentiable. If you need it to be completely smooth you can use a higher order Bezier (i.e. a higher order polynomial).

But the reality is that if the curve looks pretty smooth, the animation will be pretty smooth. By computing the change in derivative at the singular point you can figure out how big the jump is, and then try to minimize it.