linebender/spline

A more perfect curve family

raphlinus opened this issue · 0 comments

I've been feeling a bit stuck on moving this crate forward, because I feel the current draft is not perfect. I talked about that a bit in #25 but will summarize here. Basically, I feel the curves are very good for most of the parameter space, but there are a few areas in which they are not great, and I also had a feeling that some of the definitions were a bit arbitrary, lacking deep mathematical beauty.

Two specific areas that were not great:

  • A curve with high tension on one side and neutral tension on the other has a curvature dip in the middle, which I don't find appealing. It should be more like a spiral (or a semicubical parabola).

  • It can only go to a moderate degree of superellipticity (by setting tension low on the endpoints), even less than a cubic Bézier. Superellipses are extremely common in font design; classic fonts such as Eurostile, and Melior are directly inspired by them.

And the mathematical critiques:

  • There is a case analysis between >1 tension and <1 tension, with the Euler spiral in the middle. The math is pretty different in the two cases.

  • The curve family is not closed under subdivision, a property very closely related to "extensionality" in my thesis (also see related CAD 2009 paper). In addition to mathematical beauty, this affects the UI, as inserting a new subdivision point changes the existing curve.

I have considered it an open question whether extensionality (or subdivision closure) is a highly desirable property or one that can be sacrificed in a tradeoff with other properties. If the proposal in this issue succeeds, I believe that will resolve the question to the former.

The proposal, very simply, is to represent the curve as a Cesàro equation (curvature as a function of arclength) where curvature is a rational function consisting of a linear divided by quadratic polynomial, in other words:

$$\kappa(s) = \frac{as+b}{cs^2 + ds + e}$$

I have been experimenting with this some and find it promising, though haven't fully developed it. I can make some observations:

  • Subdivision is straightforward.

  • The family is characterized by the sign of c/e:

    • If $c/e &lt; 0$, there are two cusps (zeros of the denominator), corresponding to high tension. Tension is lowered by subdividing the full curve at a point away from the cusp.

    • If $c = 0$ and $d \neq 0$, there is one cusp. This corresponds to the case of high tension on one side and neutral tension on the other.

    • if $c = 0$ and $d = 0$, the curve is an Euler spiral.

    • if $c/e &gt; 0$, there is no cusp, but there is a curvature maximum, with curvature tailing to zero in the asymptotes. This corresponds to the superellipses.

  • There is in general one inflection point. This is the biggest difference from a cubic Bézier (which has two in the general case) and a 4-parameter Spiro (which has three).

  • Curvature is monotonic for much of the parameter space, which means that in usage in a spline, curvature extrema will generally be at knots. This is a desirable property, and one of the main flaws of Béziers in splines.

  • I'm fairly confident that this can be integrated analytically, resulting in a Whewell equation. There's a case analysis as above, with the result expressed in terms of $\tan^{-1}$ and $\log(1 + x^2)$ for $c/e &gt; 0$, and variations of $\tanh^{-1}$ for $c/e &lt; 0$.

This curve family has an appealing mathematical beauty, and there's a good chance it will work well in practice. It should definitely be investigated more fully.