chiark / gitweb /
sewing-table: commitid wip
[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                             + [-post_dia,+post_dia] );
66   }
67 }
68
69 m4_dnl  INREFFRAME(left_post, right_post, morevars) { body; }
70 m4_define(`INREFFRAME',`
71   length_vec = ($2) - ($1);
72   length = dist2d([0,0], length_vec);
73   length_uvec = length_vec / length;
74   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
75   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
76         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
77         [ 0,              0,              1,            0, ],
78         [ 0,              0,              0,            1, ] ];
79   $3
80   multmatrix(m)
81 ')
82
83 m4_dnl  INREFFRAME(left_post, right_post, morevars)
84 m4_dnl    INREFFRAME_EDGE { body; }
85 m4_define(`INREFFRAME_EDGE',`
86   translate([-thehd[1], -thehd[0], -round_edge_rad])
87 ')
88
89 module RoundEdge(left_post, right_post) {
90   INREFFRAME(left_post, right_post,
91               `tlength = length + thehd[1] * 2;') m4_dnl '
92     INREFFRAME_EDGE {
93     difference(){
94       rotate([0,90,0])
95         cylinder(r= round_edge_rad, h= tlength, $fn=50);
96       translate([-1, 0, -20])
97         cube([tlength+2, 20, 20]);
98     }
99   }
100 }
101
102 module RoundLeftCorner(this_post, right_post) {
103   INREFFRAME(this_post, right_post) INREFFRAME_EDGE {
104     difference(){
105       sphere(r= round_edge_rad, $fn=60);
106       translate([0,0, -20])
107         cube([20,20,20]);
108     }
109   }
110 }
111
112 module InterlockCore(r, plusth, ymir) {
113   dx = sqrt(3) * r;
114   $fn= 80;
115   translate([0, -thehd[0], plusth]){
116     mirror([0,ymir,0]){
117       mirror([0,0,1]){
118         linear_extrude(height=tile_th+plusth*2, convexity=10){
119           circle(r=r);
120           difference(){
121             translate([-dx, -0.1])
122               square([ dx*2, r/2 + 0.1 ]);
123             for (xi = [-1, 1]) {
124               translate([ xi*dx, r ])
125                 circle(r=r);
126             }
127           }
128         }
129       }
130     }
131   }
132 }
133
134 module InterlockNegative(this_post, right_post) {
135   INREFFRAME(this_post, right_post)
136     InterlockCore(interlock_negative_rad, 1, 0);
137 }
138
139 module Interlock(this_post, right_post) {
140   INREFFRAME(this_post, right_post)
141     InterlockCore(interlock_rad, 0, 1);
142 }
143
144 module TestPiece1(){ ////toplevel
145   holes = [ [-100, 0],
146             [   0, 0]
147             ];
148   difference(){
149     TileBase(holes[0], holes[1]);
150     InterlockNegative(holes[1], holes[1] + [0,1]);
151   }
152   Posts(holes);
153   RoundEdge(holes[0], holes[1]);
154   RoundEdge(holes[0] + [ 0, 0.1 ], holes[0]);
155   RoundLeftCorner(holes[0], holes[1]);
156 }
157
158 module TestPiece2(){ ////toplevel
159   holes = [ [   0, 0],
160             [  50, 0]
161             ];
162   TileBase(holes[0], holes[1]);
163   Posts(holes);
164   RoundEdge(holes[0], holes[1]);
165   Interlock(holes[0], holes[0] + [0, -1]);
166 }
167  
168 module Demo(){
169   translate([ -thehd[1], 0 ])
170     color("blue")
171     TestPiece1();
172   translate([ +thehd[1], 0 ])
173     TestPiece2();
174 }
175   
176 //TestPiece1();
177 //TestPiece2();
178 //Demo();