chiark / gitweb /
sewing-table: Use RoundCornerAdd/Cut in Tile12 too
[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 round_cnr_rad = 10;
22
23 interlock_dia = 10;
24 interlock_fine = 0.66;
25
26 interlock_fine_slope = 1.0;
27 interlock_fine_lenslop = 1.0;
28
29 demo_slop = 0.1;
30
31 // calculated
32
33 ply_edge_hole_dist = ply_edge_min + ply_hole_dia/2;
34
35 echo(str("HOLES IN PLY ctr dist from PLY edge = ", ply_edge_hole_dist));
36
37 hole_slop = (ply_hole_dia - post_dia)/2;
38 tile_hard_edge_hole_dist = ply_edge_hole_dist + hole_slop;
39
40 echo(str("HOLES IN PLY ctr dist from TILE HARD edge = ",
41          tile_hard_edge_hole_dist));
42
43 echo(str("HOLES IN PLY ctr dist from TILE ROUND edge = ",
44          tile_hard_edge_hole_dist + round_edge_rad));
45
46 thehd = [ tile_hard_edge_hole_dist, tile_hard_edge_hole_dist ];
47 thehd_tr = thehd;
48 thehd_tl = [ -thehd_tr[0], thehd_tr[1] ];
49 thehd_bl = -thehd_tr;
50 thehd_br = -thehd_tl;
51
52 interlock_rad = interlock_dia/2;
53 interlock_negative_rad = interlock_rad + 0.125;
54
55 interlock_sq_adj = 0.2; // arbitrary
56
57 module Post(){
58   mirror([0,0,1]) {
59     difference(){
60       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
61       translate([0,0, tile_th]) {
62         cylinder(r= screw_big_dia/2, h= screw_big_len);
63         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
64       }
65     }
66   }
67 }
68
69 module Posts(posts) {
70   for (p= posts) {
71     translate(concat(p, [0]))
72       Post();
73   }
74 }
75
76 module TileBase(botleft, topright){
77   size = topright - botleft;
78   botleft_post = botleft + thehd_tr;
79   topright_post = topright + thehd_bl;
80   difference(){
81     mirror([0,0,1])
82       translate(concat(botleft, [0]))
83       cube(concat(size, [tile_th]));
84     translate( concat(botleft_post, [-tile_th])
85                + 0.5 * [ post_dia, post_dia, 0 ] )
86       Commitid_BestCount_M( topright_post-botleft_post
87                             + [-post_dia,-post_dia]
88                             + [0, thehd[1]]);
89   }
90 }
91
92 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
93 m4_define(`INREFFRAME',`
94   length_vec = ($2) - ($1);
95   length = dist2d([0,0], length_vec);
96   length_uvec = length_vec / length;
97   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
98   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
99         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
100         [ 0,              0,              1,            0, ],
101         [ 0,              0,              0,            1, ] ];
102   $3
103   multmatrix(m)
104 ')
105
106 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars)
107 m4_dnl    INREFFRAME_EDGE { body; }
108 m4_define(`INREFFRAME_EDGE',`
109   translate([0,0, -round_edge_rad])
110 ')
111
112 module RoundEdge(left_cnr, right_cnr) {
113   INREFFRAME(left_cnr, right_cnr)
114     INREFFRAME_EDGE {
115     difference(){
116       rotate([0,90,0])
117         cylinder(r= round_edge_rad, h= length, $fn=50);
118       translate([-1, 0, -20])
119         cube([length+2, 20, 20]);
120     }
121   }
122 }
123
124 module RoundCornerCut(this_cnr, right_cnr) {
125   offr= round_cnr_rad - round_edge_rad;
126   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
127     difference(){
128       cube(offr*2 - 0.1, center=true);
129       translate([offr, offr, 0])
130         cylinder(center=true, h=20, r= offr);
131     }
132   }
133 }
134
135 module RoundCornerAdd(this_cnr, right_cnr) {
136   bigr = round_cnr_rad - round_edge_rad;
137   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
138     intersection(){
139       cube(bigr*2 + 0.1, center=true);
140       translate([bigr, bigr, 0])
141         rotate_extrude(convexity=10, $fn=50)
142         translate([bigr, 0])
143         difference(){
144           circle(r= round_edge_rad, $fn=50);
145           mirror([1,1])
146             square([20,20]);
147         }
148     }
149   }
150 }
151
152 module InterlockLobePlan(negative) {
153   r = negative ? interlock_negative_rad : interlock_rad;
154   ymir = negative ? 0 : 1;
155
156   dx = sqrt(3) * r;
157   $fn= 80;
158   translate([thehd[0], 0]){
159     mirror([0,ymir]){
160       circle(r=r);
161       difference(){
162         translate([-dx, -0.1])
163           square([ dx*2, r/2 + 0.1 ]);
164         for (xi = [-1, 1]) {
165           translate([ xi*dx, r ])
166             circle(r=r);
167         }
168       }
169     }
170   }
171 }
172
173 module InterlockEdgePlan(negative, nlobes, length, dosquare=true) {
174   for (lobei = [ 0 : nlobes-1 ]) {
175     lobex = (length - thehd[0]*2) * (lobei ? lobei / (nlobes-1) : 0);
176     translate([lobex, 0, 0]) {
177       InterlockLobePlan(negative);
178     }
179   }
180
181   if (dosquare) {
182     iadj = 0;
183     slotshorter = negative ? -0.1 : interlock_fine_lenslop;
184     mirror([0, negative])
185       translate([slotshorter, iadj])
186       square([length - slotshorter*2, interlock_fine + iadj*2]);
187   }
188 }
189
190 module InterlockEdge(left_cnr, right_cnr, negative=0, nlobes=2) {
191   plusth = negative * 1.0;
192   protr = interlock_fine + interlock_sq_adj;
193
194   z2 = -tile_th/2;
195   z1 = -tile_th/2 - protr / interlock_fine_slope;
196   z3 = -tile_th/2 + protr / interlock_fine_slope;
197
198   negsign = negative ? -1 : +1;
199   yprotr = negsign * protr;
200
201   INREFFRAME(left_cnr, right_cnr) {
202     for (vsect = [ // zs0            zs1      ys0,            ys1
203                   [ -tile_th-plusth, plusth,  0,              0],
204                   [ z1,              z2,      0, yprotr],
205                   [ z2,              z3,      yprotr, 0],
206                   ]) {
207       zs0 = vsect[0];
208       zs1 = vsect[1];
209       zsd = zs1-zs0;
210       ys0 = vsect[2];
211       ys1 = vsect[3];
212       ysd = ys1-ys0;
213       sl = ysd/zsd;
214       m = [ [ 1,0,   0,    0 ],
215             [ 0,1, -sl, -ys0 + negsign*interlock_sq_adj ],
216             [ 0,0,   1,  zs0 ],
217             [ 0,0,   0,    1 ] ];
218       multmatrix(m)
219         linear_extrude(height=zsd, convexity=10)
220         InterlockEdgePlan(negative, nlobes, length, !!ysd);
221     }
222   }
223 }
224
225 function TestPiece_holes2corners(holes) =
226   [ holes[0] + thehd_bl,
227     holes[1] + thehd_br,
228     holes[1] + thehd_tr,
229     holes[0] + thehd_tl ];
230
231 module TestPiece1(){ ////toplevel
232   holes = [ [-100, 0],
233             [   0, 0]
234             ];
235   corners = TestPiece_holes2corners(holes);
236   difference(){
237     union(){
238       TileBase(corners[0], corners[2]);
239       Posts(holes);
240       RoundEdge(corners[0], corners[1]);
241       RoundEdge(corners[3], corners[0]);
242     }
243     InterlockEdge(corners[1], corners[2], 1, nlobes=1);
244     RoundCornerCut(corners[0], corners[1]);
245   }
246   RoundCornerAdd(corners[0], corners[1]);
247 }
248
249 module TestPiece2(){ ////toplevel
250   holes = [ [   0, 0],
251             [  50, 0]
252             ];
253   corners = TestPiece_holes2corners(holes);
254   TileBase(corners[0], corners[2]);
255   Posts(holes);
256   RoundEdge(corners[0], corners[1]);
257   InterlockEdge(corners[3], corners[0], 0, nlobes=1);
258 }
259
260 module TestDemo(){ ////toplevel
261   translate([ -thehd[0], 0 ])
262     color("blue")
263     TestPiece1();
264   translate([ +thehd[0] + demo_slop, 0 ])
265     TestPiece2();
266 }
267   
268 function Rectangle_corners(c0, sz) =
269   [ c0 + [ 0,     0     ],
270     c0 + [ sz[0], 0     ],
271     c0 + [ sz[0], sz[1] ],
272     c0 + [ 0,     sz[1] ] ];
273
274 function Rectangle_corners2posts(c) =
275   [ c[0] + thehd_tr,
276     c[1] + thehd_tl,
277     c[2] + thehd_bl,
278     c[3] + thehd_br ];
279
280 module Tile02(){ ////toplevel
281   sz = [100,170];
282   c0 = -sz;
283   c = Rectangle_corners(c0, sz);
284   posts = Rectangle_corners2posts(c);
285   difference(){
286     union(){
287       TileBase(c[0], c[2]);
288       Posts(posts);
289       RoundEdge(c[0], c[1]);
290       RoundEdge(c[3], c[0]);
291       InterlockEdge(c[2], c[3], 0);
292     }
293     InterlockEdge(c[1], c[2], 1);
294     RoundCornerCut(c[0], c[1]);
295   }
296   RoundCornerAdd(c[0], c[1]);
297 }
298
299 module Tile12(){ ////toplevel
300   sz = [100,250];
301   c0 = [-sz[0], 0];
302   c = Rectangle_corners(c0, sz);
303   posts = Rectangle_corners2posts(c);
304   difference(){
305     union(){
306       TileBase(c[0], c[2]);
307       RoundEdge(c[2], c[3]);
308       RoundEdge(c[3], c[0]);
309       Posts(posts);
310     }
311     InterlockEdge(c[0], c[1], 1);
312     RoundCornerCut(c[2], c[3]);
313   }
314   RoundCornerAdd(c[2], c[3]);
315 }
316
317 module Demo(){ ////toplevel
318   translate(demo_slop*[-2,1]) color("blue") Tile12();
319   translate(demo_slop*[-2,0]) color("red")  Tile02();
320 }
321   
322 //TestPiece1();
323 //TestPiece2();
324 //Demo();