chiark / gitweb /
37c2be03e45e5e7a9f4dc7d393bb1b586ce1f639
[reprap-play.git] / sewing-table.scad.m4
1 // -*- C -*-
2
3 include <funcs.scad>
4
5 ply_th = 18;
6 ply_hole_dia = 15;
7 ply_edge_min = 10;
8
9 tile_th = 3;
10 post_dia = 8;
11
12 post_shorter = 1;
13
14 screw_dia = 2.2;
15 screw_big_dia = 3.6;
16 screw_big_len = 4.0;
17
18 round_edge_rad = 2.0;
19
20 interlock_dia = 10;
21
22 // calculated
23
24 ply_edge_hole_dist = ply_edge_min + ply_hole_dia/2;
25
26 echo(str("HOLES IN PLY ctr dist from edge = ", ply_edge_hole_dist));
27
28 hole_slop = (ply_hole_dia - post_dia)/2;
29 tile_hard_edge_hole_dist = ply_edge_hole_dist + hole_slop;
30 thehd = [ tile_hard_edge_hole_dist, tile_hard_edge_hole_dist ];
31
32 interlock_rad = interlock_dia/2;
33 interlock_negative_rad = interlock_rad + 0.125;
34
35 module Post(){
36   mirror([0,0,1]) {
37     difference(){
38       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
39       translate([0,0, tile_th]) {
40         cylinder(r= screw_big_dia/2, h= screw_big_len);
41         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
42       }
43     }
44   }
45 }
46
47 module Posts(posts) {
48   for (p= posts) {
49     translate([p[0], p[1], 0])
50       Post();
51   }
52 }
53
54 module TileBase(botleft_post, topright_post){
55   botleft = botleft_post - thehd;
56   size = topright_post - botleft_post + thehd * 2;
57   mirror([0,0,1])
58     translate([botleft[0], botleft[1], 0])
59     cube([size[0], size[1], tile_th]);
60 }
61
62 m4_dnl  INREFFRAME(left_post, right_post, morevars) { body; }
63 m4_define(`INREFFRAME',`
64   length_vec = ($2) - ($1);
65   length = dist2d([0,0], length_vec);
66   length_uvec = length_vec / length;
67   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
68   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
69         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
70         [ 0,              0,              1,            0, ],
71         [ 0,              0,              0,            1, ] ];
72   $3
73   multmatrix(m)
74 ')
75
76 m4_dnl  INREFFRAME(left_post, right_post, morevars)
77 m4_dnl    INREFFRAME_EDGE { body; }
78 m4_define(`INREFFRAME_EDGE',`
79   translate([-thehd[1], -thehd[0], -round_edge_rad])
80 ')
81
82 module RoundEdge(left_post, right_post) {
83   INREFFRAME(left_post, right_post,
84               `tlength = length + thehd[1] * 2;') m4_dnl '
85     INREFFRAME_EDGE {
86     difference(){
87       rotate([0,90,0])
88         cylinder(r= round_edge_rad, h= tlength, $fn=50);
89       translate([-1, 0, -20])
90         cube([tlength+2, 20, 20]);
91     }
92   }
93 }
94
95 module RoundLeftCorner(this_post, right_post) {
96   INREFFRAME(this_post, right_post) INREFFRAME_EDGE {
97     difference(){
98       sphere(r= round_edge_rad, $fn=60);
99       translate([0,0, -20])
100         cube([20,20,20]);
101     }
102   }
103 }
104
105 module InterlockCore(r, plusth, ymir) {
106   dx = sqrt(3) * r;
107   $fn= 80;
108   translate([0, -thehd[0], plusth]){
109     mirror([0,ymir,0]){
110       mirror([0,0,1]){
111         linear_extrude(height=tile_th+plusth*2, convexity=10){
112           circle(r=r);
113           difference(){
114             translate([-dx, -0.1])
115               square([ dx*2, r/2 + 0.1 ]);
116             for (xi = [-1, 1]) {
117               translate([ xi*dx, r ])
118                 circle(r=r);
119             }
120           }
121         }
122       }
123     }
124   }
125 }
126
127 module InterlockNegative(this_post, right_post) {
128   INREFFRAME(this_post, right_post)
129     InterlockCore(interlock_negative_rad, 1, 0);
130 }
131
132 module Interlock(this_post, right_post) {
133   INREFFRAME(this_post, right_post)
134     InterlockCore(interlock_rad, 0, 1);
135 }
136
137 module TestPiece1(){ ////toplevel
138   holes = [ [-100, 0],
139             [   0, 0]
140             ];
141   difference(){
142     TileBase(holes[0], holes[1]);
143     InterlockNegative(holes[1], holes[1] + [0,1]);
144   }
145   Posts(holes);
146   RoundEdge(holes[0], holes[1]);
147   RoundEdge(holes[0] + [ 0, 0.1 ], holes[0]);
148   RoundLeftCorner(holes[0], holes[1]);
149 }
150
151 module TestPiece2(){ ////toplevel
152   holes = [ [   0, 0],
153             [  50, 0]
154             ];
155   TileBase(holes[0], holes[1]);
156   Posts(holes);
157   RoundEdge(holes[0], holes[1]);
158   Interlock(holes[0], holes[0] + [0, -1]);
159 }
160  
161 module Demo(){
162   translate([ -thehd[1], 0 ])
163     color("blue")
164     TestPiece1();
165   translate([ +thehd[1], 0 ])
166     TestPiece2();
167 }
168   
169 //TestPiece1();
170 //TestPiece2();
171 //Demo();