raphlinus / spline-research

A repository for research code, papers, interactive visualizers, etc., for spline research
Apache License 2.0
219 stars 12 forks source link

Explore ways to achieve kinkless interpolation/OFV production #2

Open be5invis opened 5 years ago

be5invis commented 5 years ago

To provide correct interpolation (preventing kinks) we need some sort of C continuity at smooth knots, even if we specified the tangent direction.

raphlinus commented 5 years ago

This is a very good question. I believe it should be possible to convert from a parametrized curve in spline representation to one in piecewise Bézier. It feels like strict C1 continuity is a sufficient but perhaps not necessary condition - for example, when joining to a straight line, the velocity of the line isn't relevant. That said, it should be possible to produce C1 continuity by doing the spline to Bézier conversion in a velocity sensitive manner.

be5invis commented 5 years ago

For kink-less interpolation in VF, the generated Bezier curve should satisfy this: at each smooth joining (c' — a — b), proportion |c'-a| / |a - b| should be identical for all masters. It would be greater if this property preserves: linear combination of control knots being identical to linear combination of result Bezier curve (this is true for B spline, which is C2).

jrus commented 5 years ago

Can you explain why the parametrization matters? Interpolation probably shouldn’t just be simple lerping of positions along the curve.

Maybe would be helpful to have some specific examples of shapes you want to interpolate and what the range of acceptable outputs is.

Is the concern about existing tools for interpolating based on the Bézier output? Or interpolating a Raph-style spline per se and then rendering the intermediate shapes to Béziers separately?

be5invis commented 5 years ago

@jrus In OTVar spec it simply blends Bezier control points, so a simple G2 continuity would result in "kinks" during interpolation If the angles are different in the masters, and secondly, if the proportions between the points are different, G1 continuity would be broken after OTVar interpolation 😢 .

Ref: https://glyphsapp.com/tutorials/multiple-masters-part-2-keeping-your-outlines-compatible, § Avoiding Kinks

raphlinus commented 5 years ago

C1 continuity is a sufficient but not a necessary condition, thus I think the statement of this issue is incorrect, and I'm inclined to close the issue because of it.

That said, the higher-level goal is valid and interesting. If you're drawing masters using this spline, what is the best way to convert to a variable font? There are several ways of thinking about this problem. One is creation of piecewise Bézier curves that are compatible in the sense that they retain G1 continuity after the control points are interpolated. Within this branch of inquiry, there are further choices. We could work in cubic Béziers, in which the above discussion is relevant. But then that potentially affects the shapes of the curves (certainly the "dekink masters" tool referenced in the Glyphs tutorial will do that).

Why not instead convert to quadratic Béziers? In particular, if the conversion generates only off-curve points (not counting of course horizontal and vertical extrema, which are G1 continuous without any additional work), then the resulting curves are G1 continuous by construction, and this is also likely to be a concise representation in an OpenType font encoding.

But generating interpolation-compatible masters may not be the most interesting goal. An explicit and long-term goal of this line of work is to make a spline that behaves nicely when the spline control points are interpolated (or otherwise parametrized). The results may be better in this case than linearly interpolating the resulting Béziers; they're G2 continuous by construction. However, conversion to an OpenType variable font may be challenging. Since the spline is not linear, spline-space interpolants may not accurately match a linear interpolation of the Bézier representation. A sophisticated conversion tool would gauge the nonlinearity and produce intermediate masters as needed.

And for certain applications, including producing instances of a variable font in spline-space parametrization, or animation, doing such complicated conversion math may not be needed at all. It's basically the specific goal of replicating the existing workflow of font tools to produce OVF files that motivates the original request.

So I think there is interesting additional research to do, but I'm not convinced the specific direction stated in the issue is worthwhile.

jrus commented 5 years ago

An explicit and long-term goal of this line of work is to make a spline that behaves nicely when the spline control points are interpolated (or otherwise parametrized).

Yes, this is more what I was thinking of.

I would be curious to see what the effect is of straight interpolation of points followed by re-solving, for this spline. Also if there is more than one keyframe, interpolation need not be strictly linear, but could be e.g. a cubic spline (in weight space) fit through the keyframe positions.

I don’t have good intuition for where that would break down.

One thing that might be necessary is some kind of interpolation of spline tangent angles and then using a 4-parameter curve instead of just interpolating spline points and re-solving for the angles at every intermediate step.

Why not instead convert to quadratic Béziers? In particular, if the conversion generates only off-curve points (not counting of course horizontal and vertical extrema, which are G1 continuous without any additional work), then the resulting curves are G1 continuous by construction, and this is also likely to be a concise representation in an OpenType font encoding.

Then one thing you would have to do is make sure that the chosen split points in the generated spline are compatible.

behdad commented 5 years ago

For kink-less interpolation in VF, the generated Bezier curve should satisfy this: at each smooth joining (c' — a — b), proportion |c'-a| / |a - b| should be identical for all masters.

This is sufficient but not necessary. The correct condition is what you said, or the angles are the same.

be5invis commented 5 years ago

@behdad So perhaps "the new spline" could keep either angle or proportion depending on whether you specified a tangent angle. Looks promising ...