Reputation: 19925
I'm looking for a way to render a bunch of connected lines as a nice continuous curve in postscript. It's important that the rendered curve passes through all my points.
curveto
seems to be the only available way to draw curves, but that function requires bezier control points, which I don't have.
So, is there a way to calculate control points for my points so curveto
can be used? Preferably in postscript.
For reference, I've previously used GraphicsPath.addCurve(float[]) in .NET which does the conversion to cubic Bézier control points internally before rendering them. I'm looking for something similar in postscript.
(I am able to interpolate the points using a spline function and then render it using lots and lots of individual lines. It looks ok, but is not really a great solution)
Upvotes: 3
Views: 1278
Reputation: 19925
I solved this problem by using the code example here ("Draw a Smooth Curve through a Set of 2D Points with Bezier Primitives").
Upvotes: 1
Reputation: 80287
If you interpolate the points using a spline function, then you have some cubic equations for curve pieces. And they could be transformed to Bernstein polynomial basis to find control points of corresponding Bezier curves.
A*t^3+B*t^2+C*t+D = P0*(1-t)^3+P1*3*t*(1-t)^2+P2*3*t^2*(1-t)+P3*t^3
Make some algebra - expand the brackets, equate coefficients of identical powers of t, express P(i) through the cubic equation coefficients A,B,C,D
p0 = D
p1 = D + C/3
p2 = D + C * 2/3 + B/3
p3 = D + C + B + A
Upvotes: 2