I have a polyline that approximates a curve, and I want to draw it as a smooth curve in PostScript, which supports Bezier curve drawing. To do that, I need to generate two control points between each pair of polyline points. (I can't get the original curve from the source, just the polyline.)
I've had some success using cardinal splines from this description, but the parameters there are different from Wikipedia and GDIPlus.DrawCurve, both of which refer to tension. MS has no details, and Wikipedia has incomplete details (cardinal spline ignores x values?).
What are the formulas for the control points based on tension?
See this link http://www.ibiblio.org/e-notes/Splines/Cardinal.htm which provides simple formulas which can be used to calculate Bezier control points for a multi-segment smooth curve.
The equations are really simple but for those who don't want to repeat the calculations I'm providing my results:
Let Pi (i=1..n) be the polyline points.
First, learn how to calculate the derivatives on Pi:
P1' = (P2 - P1) / a
Pi' = (Pi+1 - Pi-1) / a (for i=2..n-1)
Pn' = (Pn - Pn-1) / a
where "a" is a coeffecient (which probably means "tension" you mentioned), for instance a=2.
Then, for each segment i (i=1..n-1) from Pi to Pi+1, Bezier control points B1i and B2i would be:
B1i = Pi + Pi'/3
B2i = Pi+1 - Pi+1'/3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With