Efficient Line Smoothing and/or Simplification

See Efficient Curve Fitting by Sarah Frisken. Also available at the author's page.


(bumped into your question while looking for same, and happened to put together something of our own)

http://willowsystems.github.com/jSignature/#/about/linesmoothing/

(SEO-compatible link to same: http://willowsystems.github.com/jSignature/%2523%252Fabout%252Flinesmoothing%252F.html)

The issue you describe is two-fold. 1. You want to 'simplify' the capture data. 2. You want to draw a nice-looking line ('fit a curve') within the points.

Simplify.js quoted above is indeed good, but it only gives you points. For jSignature we wanted to a super-efficient, non-lagging curve-fitting algorithm.

See link above for explanation of one (our) approach to fitting (Bezier aka 'cubic') curves between points. It allows you to keep the line the user drew and just lag on connecting the last 2 coordinates, or you can simplify and redraw the the whole line like that.

(Our publication of the algorithm was intentional, as to establish "prior art" and preclude petentability of the combined method. This means, we don't put our own patent yoke on the algorithm and, searched hard and did not find it to be patented elsewhere. Of course there can be some patent troll out there that may find an issue with you implementing the method, but, at least, not us. So, enjoy.)

The demo link is using 4-pixel skip on mouse movement. This is crude, but OK for real-time 'simplification' of data. If you have the luxury of capturing the whole stroke and redrawing it all, certainly, use simplify.js.