Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transferring set of points to Bezier curve

Tags:

In my WPF application I'm working on a drawing mechanism to make annotations on top of images. For now I have functionality to draw paths where my drawn path will consist of the collected points from the drawing. More closely I'm adding StylusPoints to an InkPresenter as I collect them through the MouseMoved event. The InkPresenter is set as child to a Canvas, which then is what will hold the drawings. I could also draw a LineSegment in a Path if that's any different?

My problem with this drawing is that it won't be smooth. Therefore I'd like the resulting curve to be represented as a Bezier curve. This is a technique used e.g. in Adobe Illustrator. Now; is there a way to handle this? To first build a collection of points that represents the bumpy curve drawn, and then transform this to a Bezier curve which resembles the drawn curve?

like image 505
stiank81 Avatar asked Feb 15 '10 14:02

stiank81


2 Answers

If you want to fit a curve to a set of points, think spline (of which Bezier is a subset).

Here is a PDF about how to fit a Bezier to four points, easily extended to n. This came from Don Lancaster's guru's lair, which has a great set of tutorials on Beziers.

like image 94
plinth Avatar answered Oct 03 '22 18:10

plinth


Charles Petzold has a class CanonicalSpline in the sample code for his Line Chart With Data Templates article in MSDN Magazine.

Sample Code

The key method of the class creates a PathGeometry from a set of points.

like image 42
Doug Ferguson Avatar answered Oct 03 '22 18:10

Doug Ferguson