DrawCurve / AddCurve for WPF / Cardinal Spline
For my project I need to draw Cardinal splines. Preferable the same way I was used to with the System.Drawing.Graphics or System.Drawing.Drawing2D.GraphicsPath. Not knowing much about splines, I noticed the number of PathPoints on a graphics path. The curve is drawn with beziers, so it’s some sort of string of beziers that make up this cardinal spline.
This project results in the same curves as you are used to with the graphics object (but this works with doubles not with floats). Tension and open and closed params are supported!
Anyway long story short, this project calculates control points for beziers. The curve will be draw with beziers, thus the outcome is exactly the same as with the Graphics object. I’ve seen other examples drawing the curve by them self calculating 100’s of points on the bezier it self .
Yes the graphics object does the same thing see msdn (quote:”Remarks The user must keep the original points if they are needed. The original points are converted to cubic Bézier control points internally, therefore there is no mechanism for returning the original points.”) .
If you draw a curve with 3 points, 7 points are needed to draw the curve, thus a performance gain(? not measured!) without losing the nice smoothness of the curve.
here is a screen shot:
and here is the code
comments are welcome, Can u use this, or are you missing something?
Excellent! That’s really what I needed.
I’m not familiar with spline. It would be better if you can explain the algrithom you used.
Another aritcle is http://www.codeproject.com/KB/graphics/BezierSpline.aspx?msg=2979224#xx2979224xx
This is some excellent work! After figuring out that it was a cardinal spline I was trying to create, then finding out if I was using GDI+ I could do it with one function, your code has allowed me to use WPF with the same ease! You’ve massively helped me out! Well done!