chiark / gitweb /
7e6afbf7b3f378371e4d7b06ef7d1aefbf2ddd6e
[reprap-play.git] / sewing-table.scad.m4
1 // -*- C -*-
2
3 include <funcs.scad>
4 include <commitid.scad>
5
6 ply_th = 18;
7 ply_hole_dia = 15;
8 ply_edge_min = 10;
9
10 tile_th = 3;
11 post_dia = 8;
12
13 post_shorter = 1;
14
15 screw_dia = 2.2;
16 screw_big_dia = 3.6;
17 screw_big_len = 4.0;
18
19 round_edge_rad = 2.0;
20
21 interlock_dia = 10;
22 interlock_fine = 0.66;
23
24 interlock_fine_lenslop = 1.0;
25
26 demo_slop = 0.1;
27
28 // calculated
29
30 ply_edge_hole_dist = ply_edge_min + ply_hole_dia/2;
31
32 echo(str("HOLES IN PLY ctr dist from PLY edge = ", ply_edge_hole_dist));
33
34 hole_slop = (ply_hole_dia - post_dia)/2;
35 tile_hard_edge_hole_dist = ply_edge_hole_dist + hole_slop;
36
37 echo(str("HOLES IN PLY ctr dist from TILE HARD edge = ",
38          tile_hard_edge_hole_dist));
39
40 echo(str("HOLES IN PLY ctr dist from TILE ROUND edge = ",
41          tile_hard_edge_hole_dist + round_edge_rad));
42
43 thehd = [ tile_hard_edge_hole_dist, tile_hard_edge_hole_dist ];
44 thehd_tr = thehd;
45 thehd_tl = [ -thehd_tr[0], thehd_tr[1] ];
46 thehd_bl = -thehd_tr;
47 thehd_br = -thehd_tl;
48
49 interlock_rad = interlock_dia/2;
50 interlock_negative_rad = interlock_rad + 0.125;
51
52 interlock_sq_adj = 0.2; // arbitrary
53
54 module Post(){
55   mirror([0,0,1]) {
56     difference(){
57       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
58       translate([0,0, tile_th]) {
59         cylinder(r= screw_big_dia/2, h= screw_big_len);
60         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
61       }
62     }
63   }
64 }
65
66 module Posts(posts) {
67   for (p= posts) {
68     translate(concat(p, [0]))
69       Post();
70   }
71 }
72
73 module TileBase(botleft, topright){
74   size = topright - botleft;
75   botleft_post = botleft + thehd_tr;
76   topright_post = topright + thehd_bl;
77   difference(){
78     mirror([0,0,1])
79       translate(concat(botleft, [0]))
80       cube(concat(size, [tile_th]));
81     translate( concat(botleft_post, [-tile_th])
82                + 0.5 * [ post_dia, post_dia, 0 ] )
83       Commitid_BestCount_M( topright_post-botleft_post
84                             + [-post_dia,-post_dia]
85                             + [0, thehd[1]]);
86   }
87 }
88
89 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
90 m4_define(`INREFFRAME',`
91   length_vec = ($2) - ($1);
92   length = dist2d([0,0], length_vec);
93   length_uvec = length_vec / length;
94   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
95   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
96         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
97         [ 0,              0,              1,            0, ],
98         [ 0,              0,              0,            1, ] ];
99   $3
100   multmatrix(m)
101 ')
102
103 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars)
104 m4_dnl    INREFFRAME_EDGE { body; }
105 m4_define(`INREFFRAME_EDGE',`
106   translate([0,0, -round_edge_rad])
107 ')
108
109 module RoundEdge(left_cnr, right_cnr) {
110   INREFFRAME(left_cnr, right_cnr)
111     INREFFRAME_EDGE {
112     difference(){
113       rotate([0,90,0])
114         cylinder(r= round_edge_rad, h= length, $fn=50);
115       translate([-1, 0, -20])
116         cube([length+2, 20, 20]);
117     }
118   }
119 }
120
121 module RoundLeftCorner(this_cnr, right_cnr) {
122   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
123     difference(){
124       sphere(r= round_edge_rad, $fn=60);
125       translate([0,0, -20])
126         cube([20,20,20]);
127     }
128   }
129 }
130
131 module InterlockLobePlan(negative) {
132   r = negative ? interlock_negative_rad : interlock_rad;
133   ymir = negative ? 0 : 1;
134
135   dx = sqrt(3) * r;
136   $fn= 80;
137   translate([thehd[0], 0]){
138     mirror([0,ymir]){
139       circle(r=r);
140       difference(){
141         translate([-dx, -0.1])
142           square([ dx*2, r/2 + 0.1 ]);
143         for (xi = [-1, 1]) {
144           translate([ xi*dx, r ])
145             circle(r=r);
146         }
147       }
148     }
149   }
150 }
151
152 module InterlockEdgePlan(negative, nlobes, length) {
153   for (lobei = [ 0 : nlobes-1 ]) {
154     lobex = (length - thehd[0]*2) * (lobei ? lobei / (nlobes-1) : 0);
155     translate([lobex, 0, 0]) {
156       InterlockLobePlan(negative);
157     }
158   }
159
160   iadj = interlock_sq_adj;
161   slotshorter = negative ? 0 : interlock_fine_lenslop;
162   mirror([0, negative])
163     translate([slotshorter, iadj])
164     square([length - slotshorter*2, interlock_fine + iadj*2]);
165 }
166
167 module InterlockEdge(left_cnr, right_cnr, negative=0, nlobes=2) {
168   plusth = negative * 1.0;
169
170   INREFFRAME(left_cnr, right_cnr) {
171     translate([0, 0, plusth]){
172       mirror([0,0,1]){
173         linear_extrude(height=tile_th+plusth*2, convexity=10){
174           InterlockEdgePlan(negative, nlobes, length);
175         }
176       }
177     }
178   }
179 }
180
181 function TestPiece_holes2corners(holes) =
182   [ holes[0] + thehd_bl,
183     holes[1] + thehd_br,
184     holes[1] + thehd_tr,
185     holes[0] + thehd_tl ];
186
187 module TestPiece1(){ ////toplevel
188   holes = [ [-100, 0],
189             [   0, 0]
190             ];
191   corners = TestPiece_holes2corners(holes);
192   difference(){
193     TileBase(corners[0], corners[2]);
194     InterlockEdge(corners[1], corners[2], 1, nlobes=1);
195   }
196   Posts(holes);
197   RoundEdge(corners[0], corners[1]);
198   RoundEdge(corners[3], corners[0]);
199   RoundLeftCorner(corners[0], corners[1]);
200 }
201
202 module TestPiece2(){ ////toplevel
203   holes = [ [   0, 0],
204             [  50, 0]
205             ];
206   corners = TestPiece_holes2corners(holes);
207   TileBase(corners[0], corners[2]);
208   Posts(holes);
209   RoundEdge(corners[0], corners[1]);
210   InterlockEdge(corners[3], corners[0], 0, nlobes=1);
211 }
212
213 module TestDemo(){ ////toplevel
214   translate([ -thehd[0], 0 ])
215     color("blue")
216     TestPiece1();
217   translate([ +thehd[0] + demo_slop, 0 ])
218     TestPiece2();
219 }
220   
221 function Rectangle_corners(c0, sz) =
222   [ c0 + [ 0,     0     ],
223     c0 + [ sz[0], 0     ],
224     c0 + [ sz[0], sz[1] ],
225     c0 + [ 0,     sz[1] ] ];
226
227 function Rectangle_corners2posts(c) =
228   [ c[0] + thehd_tr,
229     c[1] + thehd_tl,
230     c[2] + thehd_bl,
231     c[3] + thehd_br ];
232
233 module Tile02(){ ////toplevel
234   sz = [100,170];
235   c0 = -sz;
236   c = Rectangle_corners(c0, sz);
237   posts = Rectangle_corners2posts(c);
238   difference(){
239     TileBase(c[0], c[2]);
240     InterlockEdge(c[1], c[2], 1);
241   }
242   Posts(posts);
243   RoundEdge(c[0], c[1]);
244   RoundEdge(c[3], c[0]);
245   RoundLeftCorner(c[0], c[1]);
246   InterlockEdge(c[2], c[3], 0);
247 }
248
249 module Tile12(){ ////toplevel
250   sz = [100,250];
251   c0 = [-sz[0], 0];
252   c = Rectangle_corners(c0, sz);
253   posts = Rectangle_corners2posts(c);
254   difference(){
255     TileBase(c[0], c[2]);
256     InterlockEdge(c[0], c[1], 1);
257   }
258   Posts(posts);
259   RoundEdge(c[2], c[3]);
260   RoundEdge(c[3], c[0]);
261   RoundLeftCorner(c[2], c[3]);
262 }
263
264 module Demo(){ ////toplevel
265   translate(demo_slop*[-2,1]) color("blue") Tile12();
266   translate(demo_slop*[-2,0]) color("red")  Tile02();
267 }
268   
269 //TestPiece1();
270 //TestPiece2();
271 //Demo();