libs/Threading/Naca4.scad

changeset 0
15eac37578b7
equal deleted inserted replaced
-1:000000000000 0:15eac37578b7
1 // Naca4.scad - library for parametric airfoils of 4 digit NACA series
2 // Code: Rudolf Huttary, Berlin
3 // June 2015
4 // commercial use prohibited
5
6
7 // general use: for more examples refer to sampler.scad
8 // naca = naca digits or 3el vector (default = 12 or [0, 0, .12])
9 // L = chord length [mm] (default= 100)
10 // N = # sample points (default= 81)
11 // h = height [mm] (default= 1)
12 // open = close at the thin end? (default = true)
13 // two equivalent example calls
14 airfoil(naca = 2408, L = 60, N=1001, h = 30, open = false);
15 // airfoil(naca = [.2, .4, .32], L = 60, N=1001, h = 30, open = false);
16
17 module help()
18 {
19 echo(str("\n\nList of signatures in lib:\n=================\n",
20 "module airfoil(naca=2412, L = 100, N = 81, h = 1, open = false) - renders airfoil object\n",
21 "module airfoil(naca=[.2, .4, .12], L = 100, N = 81, h = 1, open = false) - renders airfoil object using percentage for camber, camber distance and thicknes\n",
22 "function airfoil_data(naca=12, L = 100, N = 81, open = false)\n",
23 "=================\n"));
24 }
25
26 help();
27 // this is the object
28 module airfoil(naca=12, L = 100, N = 81, h = 1, open = false)
29 {
30 linear_extrude(height = h)
31 polygon(points = airfoil_data(naca, L, N, open));
32 }
33
34 // this is the main function providing the airfoil data
35 function airfoil_data(naca=12, L = 100, N = 81, open = false) =
36 let(Na = len(naca)!=3?NACA(naca):naca)
37 let(A = [.2969, -0.126, -.3516, .2843, open?-0.1015:-0.1036])
38 [for (b=[-180:360/(N):179.99])
39 let (x = (1-cos(b))/2)
40 let(yt = sign(b)*Na[2]/.2*(A*[sqrt(x), x, x*x, x*x*x, x*x*x*x]))
41 Na[0]==0?L*[x, yt]:L*camber(x, yt, Na[0], Na[1], sign(b))];
42
43 // helper functions
44 function NACA(naca) =
45 let (M = floor(naca/1000))
46 let (P = floor((naca-M*1000)/100))
47 [M/100, P/10, floor(naca-M*1000-P*100)/100];
48
49 function camber(x, y, M, P, upper) =
50 let(yc = (x<P)?M/P/P*(2*P*x-x*x): M/(1-P)/(1-P)*(1 - 2*P + 2*P*x -x*x))
51 let(dy = (x<P)?2*M/P/P*(P-x):2*M/(1-P)/(1-P)*(P-x))
52 let(th = atan(dy))
53 [upper ? x - y*sin(th):x + y*sin(th), upper ? yc + y*cos(th):yc - y*cos(th)];
54
55

mercurial