search
Sunday, 2018 February 25, 09:57 — curve-fitting

clothoid weekend update

For context, see past posts in the curve-fitting category that I just created. To recap:

The curves I’ve been drawing are the paths made by a point moving at constant speed at an angle which is a piecewise quadratic function of path length. Curvature, the first derivative of angle, is continuous.

Such a path that hits a given sequence of dots is fully determined if it loops, but otherwise it has two degrees of freedom. For any angle and curvature at the starting dot, there is a quadratic coefficient that lets the path reach the next node, and likewise for the next. My current code starts with an estimate for the length of each segment (between two dots) and the angle at its midpoint, and uses these basis functions to fit those angles: a constant, a linear function, and a family of “solitons”: piecewise quadratics, zero outside a sequence of four dots, discontinuous in the second derivative at each of those dots. For n segments, there are n-2 solitons, so the constant and linear functions are needed to consume the last two degrees of freedom.

Eventually I noticed a flaw in this scheme: the curvature of the resulting path is the same at both ends, namely the slope of the linear component, because the solitons contribute nothing to it. That’s appropriate for ‘C’, but wrong for plenty of other strokes; in ‘S’ the end curvatures ought to have opposite sign.

The next thing I’ll try is a least-squares quadratic fit to the whole sequence, then fit the residues with solitons as before. That should be an improvement but it’s not ideal; curvature is a local feature. Perhaps I’ll think of something better later.

• comment by Anton — Thursday, 2018 March 15, 09:15

Instead of a separate least-squares phase, add a quadratic basis function and reduce the solitons by one by stretching them out to four segments, ignoring the middle breakpoint.

• comment by Anton — Monday, 2018 June 11, 08:29

A previous version, rather than fitting discrete samples exactly, used a least-squares fit to a piecewise constant. This made the quadratic cross the outer segments twice, resulting in a recurve in the final path, which I didn’t like; that is, the very tip of the path had opposite curvature to what it ought to have.

I could instead do a continuous piecewise linear fit to the piecewise constant, and then a piecewise quadratic fit to the linear; that should solve both these curvature problems, though introducing who knows what other problem.

Subscribe without commenting