Wednesday, 2018 February 28, 21:14 — curve-fitting

another problem with my clothoids

I wrote:

each curve hits alternate dots: first exactly, then with offsets pushing it toward the other curve.

I don’t think I’ve mentioned here how the offsets work.

Rather than considering the two coordinates of a point separately, I treat them as a complex number; this has huge notational conveniences.

The arc you see in my plots is a complex function of a real number. For the actual font, when I get around to making it, the outline will be the same function of a number whose imaginary part is ±½. (Curvature affects the thickness of the stroke, but by remarkably little: less than one part in twenty if the radius of curvature of the midline is 1.) So, to test whether or not a gridpoint is within the path, I find a complex number t such that f(t) is the desired point, and then compare abs(t.imag) to 0.5. (Secant method works well because the second derivative is not too big.)

The “offsets pushing it toward the other curve” are imaginary numbers: telling the path to miss each dot by a specified amount to one side or the other (halfway between the old t.imag and the new), rather than to hit any specified coordinates. I call the offset sway. What makes this approach compelling (to me) is the ease of applying it to miss white dots: if the path covers a gridpoint that it shouldn’t, I can add it to the sequence with a tag that says its sway must be more than half a unit, rather than specifying where the path must go to avoid it.

Now, for each iteration of the path, I estimate the length of each segment-arc (between two dots) and the angle at its midpoint, find the interpolating function for the angles, and then for each segment generate the Taylor series for the arc, find out how much f(t[k+1]+i*sway[k+1])-f(t[k]+i*sway[k]) differs from z[k+1]-z[k], and adjust the length and angle estimates accordingly for the next attempt.

But where sway is nonzero, the point where the segments meet on the midline – f(t[k]) without sway – keeps changing as the angles change; and I suspect that may be why this fitting phase sometimes falls into an infinite loop, failing to converge to a solution.

If that is the cause, what can I do about it? Well, I could chuck the sway concept; I hate to do that, because it’s so darn convenient when it works.

It’s hard to say which is more frustrating: knowing it’s unlikely that anyone has ever tried something so weird, or (as in another project of mine) knowing that someone somewhere has probably done exactly what I need help with and I’m unlikely to find them.

Subscribe without commenting

RSS feed for comments on this post.

Leave a comment