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