chiark / gitweb /
856035894f66a8a4878ad097b2880f87026fb19e
[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 = 1.0;
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 module Post(){
53   mirror([0,0,1]) {
54     difference(){
55       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
56       translate([0,0, tile_th]) {
57         cylinder(r= screw_big_dia/2, h= screw_big_len);
58         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
59       }
60     }
61   }
62 }
63
64 module Posts(posts) {
65   for (p= posts) {
66     translate(concat(p, [0]))
67       Post();
68   }
69 }
70
71 module TileBase(botleft, topright){
72   size = topright - botleft;
73   botleft_post = botleft + thehd_tr;
74   topright_post = topright + thehd_bl;
75   difference(){
76     mirror([0,0,1])
77       translate(concat(botleft, [0]))
78       cube(concat(size, [tile_th]));
79     translate( concat(botleft_post, [-tile_th])
80                + 0.5 * [ post_dia, post_dia, 0 ] )
81       Commitid_BestCount_M( topright_post-botleft_post
82                             + [-post_dia,-post_dia]
83                             + [0, thehd[1]]);
84   }
85 }
86
87 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
88 m4_define(`INREFFRAME',`
89   length_vec = ($2) - ($1);
90   length = dist2d([0,0], length_vec);
91   length_uvec = length_vec / length;
92   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
93   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
94         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
95         [ 0,              0,              1,            0, ],
96         [ 0,              0,              0,            1, ] ];
97   $3
98   multmatrix(m)
99 ')
100
101 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars)
102 m4_dnl    INREFFRAME_EDGE { body; }
103 m4_define(`INREFFRAME_EDGE',`
104   translate([0,0, -round_edge_rad])
105 ')
106
107 module RoundEdge(left_cnr, right_cnr) {
108   INREFFRAME(left_cnr, right_cnr)
109     INREFFRAME_EDGE {
110     difference(){
111       rotate([0,90,0])
112         cylinder(r= round_edge_rad, h= length, $fn=50);
113       translate([-1, 0, -20])
114         cube([length+2, 20, 20]);
115     }
116   }
117 }
118
119 module RoundLeftCorner(this_cnr, right_cnr) {
120   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
121     difference(){
122       sphere(r= round_edge_rad, $fn=60);
123       translate([0,0, -20])
124         cube([20,20,20]);
125     }
126   }
127 }
128
129 module InterlockLobePlan(negative) {
130   r = negative ? interlock_negative_rad : interlock_rad;
131   ymir = negative ? 0 : 1;
132
133   dx = sqrt(3) * r;
134   $fn= 80;
135   translate([thehd[0], 0]){
136     mirror([0,ymir]){
137       circle(r=r);
138       difference(){
139         translate([-dx, -0.1])
140           square([ dx*2, r/2 + 0.1 ]);
141         for (xi = [-1, 1]) {
142           translate([ xi*dx, r ])
143             circle(r=r);
144         }
145       }
146     }
147   }
148 }
149
150 module InterlockEdgePlan(negative, nlobes, length) {
151   iadj = 0.1;
152
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   slotshorter = negative ? 0 : interlock_fine_lenslop;
161   mirror([0, negative])
162     translate([slotshorter, iadj])
163     square([length - slotshorter*2, interlock_fine + iadj*2]);
164 }
165
166 module InterlockEdge(left_cnr, right_cnr, negative=0, nlobes=2) {
167   plusth = negative * 1.0;
168
169   INREFFRAME(left_cnr, right_cnr) {
170     translate([0, 0, plusth]){
171       mirror([0,0,1]){
172         linear_extrude(height=tile_th+plusth*2, convexity=10){
173           InterlockEdgePlan(negative, nlobes, length);
174         }
175       }
176     }
177   }
178 }
179
180 function TestPiece_holes2corners(holes) =
181   [ holes[0] + thehd_bl,
182     holes[1] + thehd_br,
183     holes[1] + thehd_tr,
184     holes[0] + thehd_tl ];
185
186 module TestPiece1(){ ////toplevel
187   holes = [ [-100, 0],
188             [   0, 0]
189             ];
190   corners = TestPiece_holes2corners(holes);
191   difference(){
192     TileBase(corners[0], corners[2]);
193     InterlockEdge(corners[1], corners[2], 1, nlobes=1);
194   }
195   Posts(holes);
196   RoundEdge(corners[0], corners[1]);
197   RoundEdge(corners[3], corners[0]);
198   RoundLeftCorner(corners[0], corners[1]);
199 }
200
201 module TestPiece2(){ ////toplevel
202   holes = [ [   0, 0],
203             [  50, 0]
204             ];
205   corners = TestPiece_holes2corners(holes);
206   TileBase(corners[0], corners[2]);
207   Posts(holes);
208   RoundEdge(corners[0], corners[1]);
209   InterlockEdge(corners[3], corners[0], 0, nlobes=1);
210 }
211
212 module TestDemo(){ ////toplevel
213   translate([ -thehd[0], 0 ])
214     color("blue")
215     TestPiece1();
216   translate([ +thehd[0] + demo_slop, 0 ])
217     TestPiece2();
218 }
219   
220 function Rectangle_corners(c0, sz) =
221   [ c0 + [ 0,     0     ],
222     c0 + [ sz[0], 0     ],
223     c0 + [ sz[0], sz[1] ],
224     c0 + [ 0,     sz[1] ] ];
225
226 function Rectangle_corners2posts(c) =
227   [ c[0] + thehd_tr,
228     c[1] + thehd_tl,
229     c[2] + thehd_bl,
230     c[3] + thehd_br ];
231
232 module Tile02(){ ////toplevel
233   sz = [100,170];
234   c0 = -sz;
235   c = Rectangle_corners(c0, sz);
236   posts = Rectangle_corners2posts(c);
237   difference(){
238     TileBase(c[0], c[2]);
239   }
240   Posts(posts);
241   RoundEdge(c[0], c[1]);
242   RoundEdge(c[3], c[0]);
243   RoundLeftCorner(c[0], c[1]);
244   InterlockEdge(c[2], c[3], 0);
245 }
246
247 module Tile12(){ ////toplevel
248   sz = [100,250];
249   c0 = [-sz[0], 0];
250   c = Rectangle_corners(c0, sz);
251   posts = Rectangle_corners2posts(c);
252   difference(){
253     TileBase(c[0], c[2]);
254     InterlockEdge(c[0], c[1], 1);
255   }
256   Posts(posts);
257   RoundEdge(c[2], c[3]);
258   RoundEdge(c[3], c[0]);
259   RoundLeftCorner(c[2], c[3]);
260 }
261
262 module Demo(){ ////toplevel
263   translate(demo_slop*[-2,1]) color("blue") Tile12();
264   translate(demo_slop*[-2,0]) color("red")  Tile02();
265 }
266   
267 //TestPiece1();
268 //TestPiece2();
269 //Demo();