[SciPy-dev] Fitpack, insert, and spline -> bezier conversion

Zachary Pincus zpincus@stanford....
Wed Feb 7 03:22:41 CST 2007


Hello all,

My b-spline to bezier function and patch to insert.f are both attached.

Here's an example (using Gnuplot.py):

import numpy
from scipy.interpolate import splprep,splev

u = numpy.linspace(0, 2*numpy.pi, 100, True)
x = numpy.cos(u)
y = numpy.sin(u)
circle, uout = splprep([x,y],u=u,s=0.001,per=True)
circle_plot = Gnuplot.Data(numpy.transpose(splev 
(uout,circle)),with='lines')
circle_control = Gnuplot.Data(numpy.transpose(circle[1]),with='points')
bezier_control = [Gnuplot.Data(b,with='points') for b in
   b_spline_to_bezier_series(circle,per=True)]
g = Gnuplot.Gnuplot()
g.plot(circle_plot, circle_control)
g.plot(circle_plot, *bezier_control)

sin, uout = splprep([u,y],u=u,s=0.001,per=False)
sin_plot = Gnuplot.Data(numpy.transpose(splev(uout,sin)),with='lines')
sin_control = Gnuplot.Data(numpy.transpose(sin[1]),with='points')
bezier_control = [Gnuplot.Data(b,with='points') for b in
   b_spline_to_bezier_series(sin,per=False)]
g = Gnuplot.Gnuplot()
g.plot(sin_plot, sin_control)
g.plot(sin_plot, *bezier_control)


Thanks,

Zach

-------------- next part --------------
A non-text attachment was scrubbed...
Name: b_spline_to_bezier_series.py
Type: text/x-python-script
Size: 2321 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-dev/attachments/20070207/8256ee58/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: insert.patch
Type: application/octet-stream
Size: 1408 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-dev/attachments/20070207/8256ee58/attachment.obj 
-------------- next part --------------



On Feb 6, 2007, at 7:06 PM, Robert Kern wrote:

> Zachary Pincus wrote:
>> Hello all,
>>
>> I've been working with scipy.interpolate a lot lately (hence some of
>> the noise on this list; sorry) to write some code to convert cubic
>> parametric b-splines into bezier curves (for easy output to things
>> like postscript or SVG).
>>
>> With the FITPACK 'insert' routine wrapped, this is relatively easy
>> once you figure out how, although there are a few gotchas. (Would
>> such a bit of code be useful in the scipy fitpack library?)
>
> Yes, please!
>
>> In the course of writing these conversion functions, I came upon some
>> subtle bugs in the original implementation of insert.f from netlib.
>> (They have to do with how the range into which the knot will be
>> inserted is chosen in corner cases that occur when converting
>> periodic splines to bezier curves.) I've tried contacting Dr.
>> Dierckx, but so far without luck.
>>
>> What would be the best approach to making sure that at least scipy
>> gets correct versions? Should I contact the netlib people?
>
> They're probably not in a position to accept updates from anyone  
> but the authors
> themselves, but you can try.
>
>> Should I
>> send you guys my patch and further fork the codebase?
>
> That seems like the best thing to do.
>
> -- 
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a  
> harmless enigma
>  that is made terrible by our own mad attempt to interpret it as  
> though it had
>  an underlying truth."
>   -- Umberto Eco
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-dev



More information about the Scipy-dev mailing list