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