libs/Threading/Naca4.scad

Wed, 12 Sep 2018 12:48:28 +0200

author
mdd
date
Wed, 12 Sep 2018 12:48:28 +0200
changeset 0
15eac37578b7
permissions
-rw-r--r--

initial commit of FluidSwitch prototype

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

mercurial