chiark / gitweb /
de8dbd132f094d684e23d9416998d238c017c7e5
[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
40 interlock_rad = interlock_dia/2;
41 interlock_negative_rad = interlock_rad + 0.125;
42
43 module Post(){
44   mirror([0,0,1]) {
45     difference(){
46       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
47       translate([0,0, tile_th]) {
48         cylinder(r= screw_big_dia/2, h= screw_big_len);
49         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
50       }
51     }
52   }
53 }
54
55 module Posts(posts) {
56   for (p= posts) {
57     translate(concat(p, [0]))
58       Post();
59   }
60 }
61
62 module TileBase(botleft_post, topright_post){
63   botleft = botleft_post - thehd;
64   size = topright_post - botleft_post + thehd * 2;
65   difference(){
66     mirror([0,0,1])
67       translate(concat(botleft, [0]))
68       cube(concat(size, [tile_th]));
69     translate( concat(botleft_post, [-tile_th])
70                + 0.5 * [ post_dia, post_dia, 0 ] )
71       Commitid_BestCount_M( topright_post-botleft_post
72                             + [0, thehd[1] ]
73                             + [-post_dia,-post_dia] );
74   }
75 }
76
77 m4_dnl  INREFFRAME(left_post, right_post, morevars) { body; }
78 m4_define(`INREFFRAME',`
79   length_vec = ($2) - ($1);
80   length = dist2d([0,0], length_vec);
81   length_uvec = length_vec / length;
82   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
83   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
84         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
85         [ 0,              0,              1,            0, ],
86         [ 0,              0,              0,            1, ] ];
87   $3
88   multmatrix(m)
89 ')
90
91 m4_dnl  INREFFRAME(left_post, right_post, morevars)
92 m4_dnl    INREFFRAME_EDGE { body; }
93 m4_define(`INREFFRAME_EDGE',`
94   translate(concat(-thehd, [-round_edge_rad]))
95 ')
96
97 module RoundEdge(left_post, right_post) {
98   INREFFRAME(left_post, right_post,
99               `tlength = length + thehd[0] * 2;') m4_dnl '
100     INREFFRAME_EDGE {
101     difference(){
102       rotate([0,90,0])
103         cylinder(r= round_edge_rad, h= tlength, $fn=50);
104       translate([-1, 0, -20])
105         cube([tlength+2, 20, 20]);
106     }
107   }
108 }
109
110 module RoundLeftCorner(this_post, right_post) {
111   INREFFRAME(this_post, right_post) INREFFRAME_EDGE {
112     difference(){
113       sphere(r= round_edge_rad, $fn=60);
114       translate([0,0, -20])
115         cube([20,20,20]);
116     }
117   }
118 }
119
120 module InterlockCore(r, plusth, ymir) {
121   dx = sqrt(3) * r;
122   $fn= 80;
123   translate([0, -thehd[1], plusth]){
124     mirror([0,ymir,0]){
125       mirror([0,0,1]){
126         linear_extrude(height=tile_th+plusth*2, convexity=10){
127           circle(r=r);
128           difference(){
129             translate([-dx, -0.1])
130               square([ dx*2, r/2 + 0.1 ]);
131             for (xi = [-1, 1]) {
132               translate([ xi*dx, r ])
133                 circle(r=r);
134             }
135           }
136         }
137       }
138     }
139   }
140 }
141
142 module InterlockNegative(this_post, right_post) {
143   INREFFRAME(this_post, right_post)
144     InterlockCore(interlock_negative_rad, 1, 0);
145 }
146
147 module Interlock(this_post, right_post) {
148   INREFFRAME(this_post, right_post)
149     InterlockCore(interlock_rad, 0, 1);
150 }
151
152 module TestPiece1(){ ////toplevel
153   holes = [ [-100, 0],
154             [   0, 0]
155             ];
156   difference(){
157     TileBase(holes[0], holes[1]);
158     InterlockNegative(holes[1], holes[1] + [0,1]);
159   }
160   Posts(holes);
161   RoundEdge(holes[0], holes[1]);
162   RoundEdge(holes[0] + [ 0, 0.1 ], holes[0]);
163   RoundLeftCorner(holes[0], holes[1]);
164 }
165
166 module TestPiece2(){ ////toplevel
167   holes = [ [   0, 0],
168             [  50, 0]
169             ];
170   TileBase(holes[0], holes[1]);
171   Posts(holes);
172   RoundEdge(holes[0], holes[1]);
173   Interlock(holes[0], holes[0] + [0, -1]);
174 }
175
176 module Demo(){
177   translate([ -thehd[0], 0 ])
178     color("blue")
179     TestPiece1();
180   translate([ +thehd[0], 0 ])
181     TestPiece2();
182 }
183   
184 //TestPiece1();
185 //TestPiece2();
186 //Demo();