Fitting Cubic Bézier Curves
raphlinus.github.io
raphlinus.github.io
A few years ago I faced A good many curve splitting and curve join issues when automatically building topologically complex shapes out of simpler bspline primatives — where things had to conform to various layers of constraints along the way.
Seeing something like this could have been helpful!
Ah, and because I can’t help myself, here is a sketch of the things I was building-together for this bspline generation/optimization extravaganza. Eh hem,
I’ve had much fun in related spaces...
Automatic differentiation of B-splines let’s you optimize (Newton style) Bspline curves and surfaces (and if efficiency matters not, higher dimensional bsplines I suppose).
The solver I made allowed you to compose constraints and objectives on the fly, and it would build and solve the newton system for you.
Then I tried it with interval valued control points. That worked too. Plus you get to use, e.g. Brouwer's fixed point theorem and simpler tests to exclude infeasible portions of the space. That was fun, but it needed help getting started when intervals where big. It needed a constraint solver to narrow the space first.
So I made an interval valued constraint solver based on minikanren, extended to handle interval arithmetic of course. Worked beautifully.
As a demo I had it randomly sample the design space (to a point or to a finite interval) 1D at a time, let the constraint solver kill off everything made infeasible by that choice in the other design dimensions, and then sample the next design parameter. Carrying that through the design spec arrived at a random design quickly. Then the newton solver took over and generated the geometry. At that point I realized I didn’t need the interval Newton solver for my problem... the interval constraint solver was good enough and then the real valued Newton solver could finish the job.
(Of course it could also tile the space entirely, but I’d need some fancy compute to get something back for a real problem.)
Lots of fun anyway! I still think i should make something of it, as soon as I have time... ah well
By my layman understanding the curves discussed in the following paper may be of use.
http://www.cemyuksel.com/research/interpolating_splines/a_cl...
Whether these particular splines are useful for, eg, font design, I'm not yet sold :)
If I could gift you 100 point of Karma, I would.
>Computational Geometry: Curve and Surface Modeling by Liu Ding-Yuan and Su Buqing - Chapter 2 covers Béziers. Originally published in Chinese in 1989 - Chinese shipbuilding industry splines. Maybe of interest? (IIRC you don't reference it in your thesis.)
https://twitter.com/delhanty/status/1370618402654461953
In chapter 4, they have a construction for a GC2 Bézier spline space curves - pairs of quadratics and cubics.
Generally, they cover a lot of the same material that you do in your thesis.
I didn't find anything in the book about this curve fitting problem specifically, though it's possible I missed it.
You seem a concientious author and I thought that, from having read your thesis, you were probably not aware of the book and might like to know about it.
There's interesting material in there on nonlinear splines because its a fairly old book (1989) that summarizes how they used nonlinear splines, biarcs etc in the Chinese shipbuilding industry in the decade or two priot to that.
Particularly, the survey of methods on how to choose free parameter in the biarc is not something you see much these days.
Edit: Interestingly, like you they refer to the "Euler Spiral - rather than "Cornu Spiral" or "Klothid"/"Clothoid". Another name, I see in literature from that era is "LINCE" (Linear Curavture Element) such as in [0].
[0] Two-dimensional curve synthesis using linear curvature elements https://www.sciencedirect.com/science/article/abs/pii/001044...
Shipbuilding has a long connection with splines, long before digital computation. The Autokon system was built by Even Mehlum in the 60s for the Norwegian shipbuilding industry, and this was a pioneering application of the Euler spiral spline. It's not surprising to learn the Chinese shipbuilding industry was also doing interesting things and engaging with mathematicians such as Liu Ding-Yuan and Su Buqing.
Say if instead, one wanted the reverse - an Euler spiral approximation that was exact at the endpoints and was allowed errors in the middle. Do you have any idea of the best method to achieve that?
(So to make it concrete, if one had end points and end tangents that were compatible with fitting a spiral, which should define a unique Euler spiral segment. Let's say it's parameterized by turning angle rather than length.)
That said, there are other things you can do. Since the derivatives of an Euler spiral are easy enough to compute analytically, you could do Hermite interpolation with a polynomial of arbitrarily high order. I've worked out how to do it for quintic, which is pretty tractable, but I'm sure it could be done even higher. That definitely meets your stated goal (precise at endpoints, sloppy in the middle), but the order of convergence of a quintic is only moderately good compared to the higher order polynomials in spiro.
>The simplicity of the arc as primitive curve has some nice features though, for example the fact that parallel curve is nearly trivial.
Yes.
Also, IIRC, Alexey Kurnosenko uses them in one of his papers to bound the regions of when it's possible to fit a spiral to end point data,
Chapter III Parametric Cubic Spline Curves
4 A Theorem Concerning Segments of Parametric Cubic Curves
Also, it's based on earlier papers by Su Buqing from around 1977.
I cheated with SVG filters to get something like the effect I wanted but I’ll definitely be revisiting this to refine it.
Thank you for sharing!
Raph, do you maintain any kind of full path parameter through this process, and if so are there any gotchas or tricks? Are there even any choices you can make? I’m not sure, and I’m asking before thinking about it carefully, so that might be a dumb question. I’m just wondering out loud what happens when merging two segments of different lengths and whether there are any ways to try to preserve roughly the same path parameterization as before merging.
Probably because I’m not very familiar with the prior work, I’m not sure I followed where the area metric came from. Is fitting area a popular way to do this in the prior work, or a recent development, or is that your own new finding?
The technique should definitely work for path merging, that's a primary motivation. I'm not sure I understand your other questions. It'll probably be clearer when I release some code that implements this algorithm, though I'm not making any promises when that might be.
In my case, I am trying to quantify the difference in shape between outlines of rock carvings on Stonehenge (purported to be axeheads) and outlines of several different styles of actual bronze age axeheads.
I'm sorry you got lost. This particular technique is fairly deeply mathematical, and to really appreciate it I guess you need some grounding in the relevant math as well as familiarity with the curve and geometry concepts. I tried to get the intuition across as much as possible, certainly as opposed to the "wall of greek" I see in a lot of academic papers.
This might well turn into an academic paper - I have as a goal to do one or two of those a year. But I also really wanted to do a blog post because I think this could be useful now, and also because the insight about triplets of similar cubic Béziers is something that might be useful even to artists and designers as opposed to tool builders.
Personally I don't think cubic Béziers per se seem like an especially good CAM primitive, but they are ubiquitous in 2d computer graphics, so they might be convenient for that reason.