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