libs/Threading/Naca_sweep.scad

Wed, 12 Sep 2018 13:23:19 +0200

author
mdd
date
Wed, 12 Sep 2018 13:23:19 +0200
changeset 1
a159ad715fe0
parent 0
15eac37578b7
permissions
-rw-r--r--

final assembly with correct oring sizes and tube diameters

0
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
1 // Naca4_sweep.scad - sweep library
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 use <Naca4.scad>
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
7
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
8 //example1();
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
9 //rotate([80, 180, 130])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
10 example();
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
11
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
12 // sweep from NACA1480 to NACA6480 (len = 230 mm, winding y,z = 80°
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
13 // sweeps generates a single polyhedron from multiple datasets
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
14 module example()
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
15 {
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
16 N = 40;
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
17 sweep(gen_dat(N=5, dz=1,N=N));
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
18
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
19 // specific generator function
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
20 function gen_dat(M=10,dz=.1,N=10) = [for (i=[1:dz:M])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
21 let( L = length(i))
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
22 let( af = vec3D(
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
23 airfoil_data([.1,.5,thickness(i)], L=length(i), N = N)))
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
24 T_(-L/2, 0, (i+1)*2, af)]; // translate airfoil
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
25
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
26 function thickness(i) = .5*sin(i*i)+.1;
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
27 function length(i) = (60+sin(12*(i-3))*30);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
28 }
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
29
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
30 module help()
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
31 {
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
32 echo(str("\n\nList of signatures in lib:\n=================\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
33 "sweep(dat, convexity = 5, showslices = false, plaincaps = true) // dat - vec of vec2, with vec1 = airfoil_data\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
34 "function vec3D(v, z=0) // expand vec2 to vec3",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
35 "function rot(w=0, p) // rotate vec2",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
36 "function T_(x=0, y=0, z=0, v) // translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
37 "function R_(x=0, y=0, z=0, v) // rotates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
38 "function Rx_(x=0, v) // x-rotates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
39 "function Ry_(y=0, v) // y-rotates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
40 "function Rz_(z=0, v) // z-rotates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
41 "function T_(x=0, y=0, z=0, v) // translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
42 "function Tx_(x=0, v) // x-translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
43 "function Ry_(y=0, v) // y-translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
44 "function Rz_(z=0, v) // z-translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
45 "function S_(x=0, y=0, z=0, v) // scales vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
46 "function Sx_(x=0, v) // x-translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
47 "function Sy_(x=0, v) // y-translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
48 "function Sz_(x=0, v) // z-translates vec of vec3\n",
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
49 "=================\n"));
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
50 }
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
51
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
52
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
53 // generate polyhedron from multiple airfoil_datasets
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
54 // dat - vec of vec1, with vec1 = simple polygon like airfoil_data, > 3 points per dataset expected
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
55 module sweep(dat, convexity = 5, showslices = false, plaincaps = true)
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
56 {
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
57 n = len(dat); // # datasets
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
58 l = len(dat[0]); // points per dataset
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
59 if(l<=3)
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
60 echo("ERROR: sweep() expects more than 3 points per dataset");
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
61 else
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
62 {
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
63 if(n==1)
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
64 polyhedron(points = dat[0], faces = [count(l-1, 0)]);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
65 else{
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
66 first = plaincaps?[count(l-1, 0)]:
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
67 faces_polygon(l, true); // triangulate first dataset
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
68 last = plaincaps?[count((n-1)*l,(n)*l-1)]:
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
69 faces_shift((n-2)*l, faces_polygon(l, false)); // triangulate last dataset
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
70 if (showslices)
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
71 for(i=[0:n-1])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
72 sweep([dat[i]]);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
73 else
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
74 if (n<2) // this case is also used recursively for showslices
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
75 polyhedron(points = flat(), faces = last, convexity = 5);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
76 else
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
77 {
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
78 polyhedron(points = flat(),
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
79 faces = concat(first, last, faces_sweep(l,n)), convexity = 5);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
80 }
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
81 }
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
82 }
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
83 function count(a, b) = let(st = (a<b?1:-1))[for (i=[a:st:b]) i];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
84 function faces_shift(d, dat) = [for (i=[0:len(dat)-1]) dat[i] + [d, d, d]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
85 function flat() = [for (i=[0:n-1], j=[0:l-1]) dat[i][j]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
86 }
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
87
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
88 function del(A, n) = [for(i=[0:len(A)-1]) if (n!=i)A[i]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
89
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
90 //// composition stuff for polyhedron
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
91 function faces_sweep(l, n=1) = let(M = n*l)
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
92 concat([[0,l,l-1]], // first face
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
93 [for (i=[0:l*(n-1)-2], j = [0,1])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
94 j==0? [i, i+1, (i+l)] : [i+1, (i+l+1), i+l]],
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
95 [[n*l-1, (n-1)*l-1, (n-1)*l]]) // last face
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
96 ;
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
97
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
98 function faces_polygon(l, first = true) = let(odd = (l%2==1), d=first?0:l)
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
99 let(res = odd?concat([[d,d+1,d+l-1]],
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
100 [for (i=[1:(l-3)/2], j=[0,1])(j==0)?[d+i,d+i+1,d+l-i]:[d+i+1,d+l-i-1, d+l-i]]):
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
101 [for (i=[0:(l-4)/2], j=[0,1])(j==0)?[d+i,d+i+1,d+l-i-1]:[d+i+1,d+l-i-2, d+l-i-1]])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
102 first?facerev(res):res;
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
103
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
104 function facerev(dat) = [for (i=[0:len(dat)-1]) [dat[i][0],dat[i][2],dat[i][1]]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
105
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
106
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
107
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
108 //// vector and vector set operation stuff ///////////////////////
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
109 //// Expand 2D vector into 3D
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
110 function vec3D(v, z=0) = [for(i = [0:len(v)-1])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
111 len(v[i])==2?[v[i][0], v[i][1], z]:v[i]+[0, 0, z]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
112
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
113 // Translation - 1D, 2D, 3D point vector //////////////////////////
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
114 // vector along all axes
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
115 function T_(x=0, y=0, z=0, v) = let(x_ = (len(x)==3)?x:[x, y, z])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
116 [for (i=[0:len(v)-1]) T__(x_[0], x_[1], x_[2], p=v[i])];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
117 /// vector along one axis
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
118 function Tx_(x=0, v) = T_(x=x, v=v);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
119 function Ty_(y=0, v) = T_(y=y, v=v);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
120 function Tz_(z=0, v) = T_(z=z, v=v);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
121 /// point along all axes 1D, 2D, 3D allowed
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
122 function T__(x=0, y=0, z=0, p) = len(p)==3?p+[x, y, z]:len(p)==2?p+[x, y]:p+x;
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
123
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
124 //// Rotation - 2D, 3D point vector ///////////////////////////////////
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
125 // vector around all axes
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
126 function R_(x=0, y=0, z=0, v) = // 2D vectors allowed
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
127 let(x_ = (len(x)==3)?x:[x, y, z])
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
128 len(v[0])==3?Rx_(x_[0], Ry_(x_[1], Rz_(x_[2], v))):
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
129 [for(i = [0:len(v)-1]) rot(x_[2], v[i])];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
130 // vector around one axis
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
131 function Rx_(w, A) = A*[[1, 0, 0], [0, cos(w), sin(w)], [0, -sin(w), cos(w)]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
132 function Ry_(w, A) = A*[[cos(w), 0, sin(w)], [0, 1, 0], [-sin(w), 0, cos(w)]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
133 function Rz_(w, A) = A*[[cos(w), sin(w), 0], [-sin(w), cos(w), 0], [0, 0, 1]];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
134
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
135
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
136 //// Scale - 2D, 3D point vector ///////////////////////////////////
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
137 // vector along all axes
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
138 function S_(x=1, y=1, z=1, v) =
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
139 [for (i=[0:len(v)-1]) S__(x,y,z, v[i])];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
140 // vector along one axis
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
141 function Sx_(x=0, v) = S_(x=x, v=v);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
142 function Sy_(y=0, v) = S_(y=y, v=v);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
143 function Sz_(z=0, v) = S_(z=z, v=v);
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
144 // single point in 2D
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
145 function S__(x=1, y=1, z=1, p) =
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
146 len(p)==3?[p[0]*x, p[1]*y, p[2]*z]:len(p)==2?[p[0]*x+p[1]*y]:[p[0]*x];
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
147
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
148
15eac37578b7 initial commit of FluidSwitch prototype
mdd
parents:
diff changeset
149

mercurial