Download code

Jump to: navigation, search

Back to Cubic_spline_(Python)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

cubicspline.py

 1 # The authors of this work have released all rights to it and placed it
 2 # in the public domain under the Creative Commons CC0 1.0 waiver
 3 # (http://creativecommons.org/publicdomain/zero/1.0/).
 4 # 
 5 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 # 
13 # Retrieved from: http://en.literateprograms.org/Cubic_spline_(Python)?oldid=16028
14 
15 from numpy import *
16 
17 s = arange(257)/256.0
18 z = s[::-1]
19 b = transpose(array((z*z*z,
20                    3*z*z*s, 
21                    3*z*s*s,
22                      s*s*s)))
23 def cubicspline(c,t): return dot(b[t],c)
24 if __name__ == "__main__":
25         cs = reshape(array([
26         533,179, 533,179, 483,0, 483,0,
27         483,0, 483,0, 28,0, 28,0,
28         28,0,28,0, 28,24, 28,24,
29         28,24, 28,24, 81,24, 81,24,
30         81,24, 109,24, 117,53, 117,76,
31         117,76, 117,76, 117,600, 117,600,
32         117,600, 117,618, 99,637, 81,637,
33         81,637, 81,637, 28,637, 28,637,
34         28,637, 28,637, 28,661, 28,661,
35         28,661, 28,661, 259,661, 259,661,
36         259,661, 259,661, 259,637, 259,637,
37         259,637, 259,637, 206,637, 206,637,
38         206,637, 187,637, 172,618, 172,600,
39         172,600, 172,600, 172,73, 172,73,
40         172,73, 172,50, 184,23, 210,23,
41         210,23, 210,23, 330,23, 330,23,
42         330,23, 416,23, 495,99, 518,179,
43         518,179, 518,179, 533,179, 533,179,
44         ]),(-1,4,2))
45 
46         print "%!"
47         print "20 200 translate"
48         print ".8 .8 scale"
49         print "%d %d moveto" % tuple(cs[0][0])
50 
51         for (x,y) in [cubicspline(c,16*t) for c in cs for t in arange(17)]:
52                 print x,y,"lineto"
53 
54         print "stroke showpage"


hijacker
hijacker
hijacker
hijacker