chiark / gitweb /
e8f6b7a7c68a4e79ee2c6310a0a7200708d48609
[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.25;
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) {
106   translate([0, -thehd[0], 1]){
107     mirror([0,0,1]){
108       linear_extrude(height=tile_th+2){
109         circle(r=r, $fn=40);
110       }
111     }
112   }
113 }
114
115 module InterlockNegative(this_post, right_post) {
116   INREFFRAME(this_post, right_post)
117     InterlockCore(interlock_negative_rad);
118 }
119
120 module TestPiece1(){
121   holes = [ [-100, 0],
122             [   0, 0]
123             ];
124   difference(){
125     TileBase(holes[0], holes[1]);
126     InterlockNegative(holes[1], holes[1] + [0,1]);
127
128   }
129   Posts(holes);
130   RoundEdge(holes[0], holes[1]);
131   RoundEdge(holes[0] + [ 0, 0.1 ], holes[0]);
132   RoundLeftCorner(holes[0], holes[1]);
133 }
134
135 TestPiece1();