# Spline interpolation - nSpline() Classic List Threaded 13 messages Open this post in threaded view
|

## Spline interpolation - nSpline()

 For anybody who is interested, I have meanwhile published my *nSpline()* function. http://www.thingiverse.com/thing:1208001 Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 Hello Parkinbod, very interesting. I spend some time on finding how interpolation works and begin to understand what you are doing. However there is a small bug in your horn file causing an unfinished circle: function circle_(r, N) =     [   // input:   radius r and the number of vectors         // output:  N vectors on edge of circle with radius r         for(i=[0:N-1])             // internal help variabel w = angle             let(w = i*360/N)             // produce x and y             [r*sin(w), r*cos(w)]     ];this should be: function circle_(r, N) =     [   // input:   radius r and the number of vectors         // output:  N vectors on edge of circle with radius r         for(i=[0:N-1])             // internal help variabel w = angle             let(w = i*360/(N-1))             // produce x and y             [r*sin(w), r*cos(w)]     ];
Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 Thanks for looking at the code. I don't see a bug, as polygon() closes a figure itself. Both versions seem to work, but yours produces the initial point twice - don't know whether polygon treats this case internally. But let's see what happens: difference() {   polygon(points = circle_(6, 5));   polygon(points = circle1_(3, 5)); } function circle_(r, N) = [   for(i=[0:N-1]) let(w = i*360/N)     [r*sin(w), r*cos(w)]]; function circle1_(r, N) = [   for(i=[0:N-1]) let(w = i*360/(N-1))     [r*sin(w), r*cos(w)]]; Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 This post was updated on . Try this one: //////////////////////////////////////////////////// // horn.scad - demo for mulivariate splines // Implementation: Rudolf Huttary (c), Berlin //  Dezember 2015 //  commercial use prohibited use use   A = [//x,   y,z,      r, angle   // data outer skin       [0,   0,0,      20,    0],       [20,  0,200,    40,  -10],       [60,  0,300,    70,  -60],       [68,  0,310,    100, -62],       [68+1,0,310+.6, 100, -62],   ]; d = 1;  // thickness A1 = [                           // data inner skin   [-0.001,0,-0.001, 20-d, 0],       [20,    0,200,    40-d, -10],   [60,    0,300,    70-d, -60],   [68,    0,310,    100-d, -62],   [68+1.1,0,310+.7, 100-d, -62],   ]; B = nSpline(A,20);    // outer skin B1 = nSpline(A1,20);  // inner skin C = gen_dat(B, 80);   // generate data C1 = gen_dat(B1, 80); // generate data difference() {   sweep(C);   sweep(C1); } function circle_(r, N) = [   for(i=[0:N-1]) let(w = i*360/N)     [r*sin(w), r*cos(w)]];     function gen_dat(S, N) =    [ for (i=[0:len(S)-1])        let(dat = Ry_(S[i], vec3D(circle_(S[i], N))))         T_(S[i], S[i], S[i], dat)];
Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 Ah, good point! Thanks for putting me on the right track! It is not the circle, but some strange habit of my sweep() function, which doesn't close polygons itself. I should give it a review some day to also work with standard semantics. As expected the equivalent function skin() works correctly with both versions: use use   use A = [//x,   y,z,      r, angle   // data outer skin       [0,   0,0,      20,    0], ... difference() {   skin(C);   skin(C1); } Your version seems to work with both, but does a N-1-polygon only. To please sweep(), skin() and the N-semantics: function circle_(r, N) = [   for(i=[0:N]) let(w = i*360/N)     [r*sin(w), r*cos(w)]];
Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 In reply to this post by Parkinbot I tried the sweep again with circles giving another small problem. This is the file I use: curved_barrel_bes_clarinet_v4.scadI also tried this with skin. Resulting in this messags: Saved backup file: C:/Users/Eigenaar/Documents/OpenSCAD/backups/curved barrel bes clarinet v3-backup-mpfy1924.scad Compiling design (CSG Tree generation)... ECHO: "l_barrel", 60.9279 ECHO: "len", 100 WARNING: Ignoring unknown function 'to_3d'. ERROR: Recursion detected calling function 'len' Compiling design (CSG Products generation)... Geometries in cache: 270 Geometry cache size in bytes: 23560776 CGAL Polyhedrons in cache: 15 CGAL cache size in bytes: 38279532 Compiling design (CSG Products normalization)... Normalized CSG tree has 0 elements Compile and preview finished. Total rendering time: 0 hours, 0 minutes, 0 seconds
Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 Thanks again for producing test cases. I haven't had time to revise the code. But skin() works with me. It includes some more libs, which should be in the path ... This will solve your problem - Rudolf
Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 Hi Rudolf, no problem. But I think I miss some essential libs for skin to work.
Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

Open this post in threaded view
|

## Re: Spline interpolation - nSpline()

 In reply to this post by Parkinbot From my experiments, it doesn't matter if the start point is defined once or twice. Larry