chiark / gitweb /
fe32ca5c4f193d6c8c3ed8ffca85abebdcdc4895
[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   echo(botleft_post, topright_post);
71   difference(){
72     mirror([0,0,1])
73       translate(concat(botleft, [0]))
74       cube(concat(size, [tile_th]));
75     translate( concat(botleft_post, [-tile_th])
76                + 0.5 * [ post_dia, post_dia, 0 ] )
77       Commitid_BestCount_M( topright_post-botleft_post
78                             + [0, thehd[1] ]
79                             + [-post_dia,-post_dia] );
80   }
81 }
82
83 m4_dnl  INREFFRAME(left_post, right_post, morevars) { body; }
84 m4_define(`INREFFRAME',`
85   length_vec = ($2) - ($1);
86   length = dist2d([0,0], length_vec);
87   length_uvec = length_vec / length;
88   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
89   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
90         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
91         [ 0,              0,              1,            0, ],
92         [ 0,              0,              0,            1, ] ];
93   $3
94   multmatrix(m)
95 ')
96
97 m4_dnl  INREFFRAME(left_post, right_post, morevars)
98 m4_dnl    INREFFRAME_EDGE { body; }
99 m4_define(`INREFFRAME_EDGE',`
100   translate(concat(-thehd, [-round_edge_rad]))
101 ')
102
103 module RoundEdge(left_post, right_post) {
104   INREFFRAME(left_post, right_post,
105               `tlength = length + thehd[0] * 2;') m4_dnl '
106     INREFFRAME_EDGE {
107     difference(){
108       rotate([0,90,0])
109         cylinder(r= round_edge_rad, h= tlength, $fn=50);
110       translate([-1, 0, -20])
111         cube([tlength+2, 20, 20]);
112     }
113   }
114 }
115
116 module RoundLeftCorner(this_post, right_post) {
117   INREFFRAME(this_post, right_post) 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 InterlockCore(r, plusth, ymir) {
127   dx = sqrt(3) * r;
128   $fn= 80;
129   translate([0, -thehd[1], plusth]){
130     mirror([0,ymir,0]){
131       mirror([0,0,1]){
132         linear_extrude(height=tile_th+plusth*2, convexity=10){
133           circle(r=r);
134           difference(){
135             translate([-dx, -0.1])
136               square([ dx*2, r/2 + 0.1 ]);
137             for (xi = [-1, 1]) {
138               translate([ xi*dx, r ])
139                 circle(r=r);
140             }
141           }
142         }
143       }
144     }
145   }
146 }
147
148 module InterlockNegative(this_post, right_post) {
149   INREFFRAME(this_post, right_post)
150     InterlockCore(interlock_negative_rad, 1, 0);
151 }
152
153 module Interlock(this_post, right_post) {
154   INREFFRAME(this_post, right_post)
155     InterlockCore(interlock_rad, 0, 1);
156 }
157
158 function TestPiece_holes2corners(holes) =
159   [ holes[0] + thehd_bl,
160     holes[1] + thehd_br,
161     holes[0] + thehd_tl,
162     holes[1] + thehd_tr ];
163
164 module TestPiece1(){ ////toplevel
165   holes = [ [-100, 0],
166             [   0, 0]
167             ];
168   corners = TestPiece_holes2corners(holes);
169   difference(){
170     TileBase(corners[0], corners[3]);
171     InterlockNegative(holes[1], holes[1] + [0,1]);
172   }
173   Posts(holes);
174   RoundEdge(holes[0], holes[1]);
175   RoundEdge(holes[0] + [ 0, 0.1 ], holes[0]);
176   RoundLeftCorner(holes[0], holes[1]);
177 }
178
179 module TestPiece2(){ ////toplevel
180   holes = [ [   0, 0],
181             [  50, 0]
182             ];
183   corners = TestPiece_holes2corners(holes);
184   TileBase(corners[0], corners[3]);
185   Posts(holes);
186   RoundEdge(holes[0], holes[1]);
187   Interlock(holes[0], holes[0] + [0, -1]);
188 }
189
190 module Demo(){ ////toplevel
191   translate([ -thehd[0], 0 ])
192     color("blue")
193     TestPiece1();
194   translate([ +thehd[0], 0 ])
195     TestPiece2();
196 }
197   
198 //TestPiece1();
199 //TestPiece2();
200 //Demo();