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