Drawing a smooth line from tablet input

When the user drags the stylus onto the tablet, you get a series of coordinates. You want to approximate the path of the pen with a smooth line, followed by only a few sample points. How do you do it?

In other words, how would you make a nice, smooth, flexible line when the user draws it with their tablet? Simply connecting points with straight lines is not enough. Real-world drawing programs do a much better job of bending a line, no matter how close or far away from the sample point. Some even let you give them a number to indicate the amount of anti-aliasing to be done, taking into account awkward grips and hands. Where can I learn to do this?

+2


source to share


2 answers


I know this is an old question, but I had the same problem and came up with two different solutions:

  • The first approach is to use two resolutions, one where the user inserts waypoints connecting them to straight lines. Second, when the user finishes the stroke, remove the lines and draw and splicate them. It should be smoother than straight lines.

  • The second approach is to smooth the new points using a weighted average from the previous sample. Thus, every time you get a new selected point [x1, y1], instead of drawing it directly, you take the previous selected point [x2, y2] and create a new intermediate point with a weighted average of the two points. The pseudocode could be something like this:

    newPoint = [x1, y1]; oldPoint = [x2, y2];

    point2Paint = [(x1 * 0.3) + (x2 * 0.7), (y1 * 0.3) + (y2 * 0.7)]; oldPoint = newPoint;

    As 0.7 and 0.3 coefficients for the weighted average (you can change them to get the smoothing you want :)

Hope this helps



UPDATE Dec 13: Here is an article explaining the different drawing techniques, there are good concepts that can be applied (anti-aliasing, bezier curves, smooth joints)

http://perfectionkills.com/exploring-canvas-drawing-techniques/

+2


source


I've never had to do these (for academic purposes only), but you can take a look at the wikipedia interpolation article,

Extracted from the article:



Interpolation

is a method of plotting new data points within the range of a discrete set of known data points.

In engineering and science, there is often a series of data points obtained by sampling or experimentation and trying to construct a function that matches those data points exactly. This is called curve analysis or regression analysis. Interpolation is a specific case of curve fitting where the function must go exactly through the data points.

Hope it helps.

0


source







All Articles