chiark / gitweb /
4441b2a5713508b2123d40eef0d139405c93061d
[reprap-play.git] / ksafe-base.scad
1 // -*- C -*-
2
3 // from actual ksafe
4 bolt_above = 8.50 - 0.50;
5 bolthole_height = 4.24 + 1.00;
6 wall_thick = 4.50;
7 bolthole_width = 16.62 + 2.00;
8 main_sz = 150.56 + 0.75;
9 cnr_rad = 13.5; // approx
10 lidinner_thick_allow = 20.78 + 0.50;
11
12 // other parameters
13 web_thick = 4;
14 web_height = 20; // excluding wall and base thick
15 bolthole_rhs = 20;
16 bolthole_lhs = 20;
17 boltreinf_thick = 6;
18 anchor_wall_space = 25;
19 base_thick = 4;
20 space = 25;
21 anchor_thick = 4;
22 anchor_rad = 4;
23 bevel = 8;
24 string_slot = 3.0;
25 string_depth = 6.0;
26
27 // ----- calculated -----
28
29 hsz = main_sz/2;
30
31 gppA = [0,0];
32 gppB = gppA - [ wall_thick, 0 ];
33
34 gppL = [ gppB[0], -(lidinner_thick_allow + space + base_thick) ];
35
36 yw1 = -web_thick/2;
37 yw2 = yw1 - bolthole_rhs;
38 yw3 = yw2 - anchor_thick;
39 yw4 = yw3 - anchor_wall_space;
40 yw5 = yw4 - wall_thick;
41 yw6 = -(hsz - cnr_rad + 0.1);
42
43 yw10 = web_thick/2;
44 yw11 = yw2 + anchor_wall_space;
45 yw12 = yw11 + wall_thick;
46 yw13 = -yw6;
47
48 // anchor
49
50 anchor_b = anchor_thick + anchor_rad;
51 appM = gppL + anchor_b * [1,1];
52
53 a_bevel = 2 * anchor_b * (1 + sqrt(0.5));
54
55 module upp_app_Vars(t_bevel){
56   $xppE = gppL + t_bevel * [0,1];
57   $xppF = gppL + t_bevel * [1,0];
58
59   $xppJ = $xppE + wall_thick * [ 1, tan(22.5) ];
60   $xppI = $xppF + base_thick * [ tan(22.5), 1 ];
61
62   // must pass a_bevel for t_bevel for these to be valid
63   $gppP = gppA + [0,-1] * lidinner_thick_allow;
64   $gppQ = $gppP + [1,-1] * web_height;
65   $gppR = $xppJ + [ 1, tan(22.5) ] * web_height;
66   $gppS = $xppI + [ tan(22.5), 1 ] * web_height;
67   $gppT = [ $gppQ[0], $xppE[1] ];
68
69   children();
70 }
71
72 module upp_app_Profile(){
73   polygon([ gppA,
74             gppB,
75             $xppE,
76             $xppF,
77             $xppF + [1,0],
78             $xppI + [1,0],
79             $xppJ ],
80           convexity=10);
81 }
82
83
84 module UsualProfile(){
85   upp_app_Vars(bevel) upp_app_Profile();
86 }
87
88 module NearAnchorProfile(){
89   upp_app_Vars(a_bevel) upp_app_Profile();
90 }
91
92 module AnchorProfile(){
93   upp_app_Vars(a_bevel) {
94
95     upp_app_Profile();
96
97     difference(){
98       hull(){
99         polygon([ $xppE,
100                   $xppF,
101                   $xppF + [0,1],
102                   $xppE + [1,0] ],
103           convexity=10);
104         translate(appM) circle(r= anchor_b);
105       }
106       translate(appM) circle(r= anchor_rad);
107     }
108   }
109 }
110
111 module AnchorWallProfile(){
112   UsualProfile();
113   NearAnchorProfile();
114   hull(){
115     for (bev = [bevel, a_bevel]) {
116       upp_app_Vars(bev) {
117         polygon([ $xppE,
118                   $xppF,
119                   $xppI,
120                   $xppJ ],
121           convexity=10);
122       }
123     }
124   }
125 }
126
127 module WebProfile(){
128   upp_app_Vars(a_bevel){
129     if ($gppR[1] <= $gppP[1]) {
130       polygon([ $gppP,
131                 $xppE,
132                 $gppT,
133                 $gppQ ]);
134       polygon([ $gppP,
135                 $xppE,
136                 $xppF,
137                 $gppS,
138                 $gppR ],
139           convexity=10);
140     } else {
141       polygon([ $gppP,
142                 $xppE,
143                 $xppF,
144                 $gppS,
145                 $gppP + web_height * [1,0] ],
146           convexity=10);
147     }
148     polygon([ $gppS,
149               $xppF,
150               $xppF + [1,0],
151               $gppS + [1,0] ],
152           convexity=10);
153   }
154 }
155
156 module SomeBaseProfile(I, F){
157   polygon([ I,
158             F,
159             [ hsz+1, F[1] ],
160             [ hsz+1, I[1] ] ]);
161 }
162
163 module BaseProfile(){
164   SomeBaseProfile($xppI, $xppF);
165 }
166
167 module SWalls(ymin, ymax, t_bevel) {
168   upp_app_Vars(t_bevel) {
169     translate([0,ymin,0])
170       mirror([0,1,0])
171       rotate([90,0,0])
172       linear_extrude(height= ymax-ymin, convexity=10)
173       for (xm=[0,1])
174         mirror([xm,0])
175           translate([-hsz, 0])
176             children();
177   }
178 }
179
180 module AtTwoCorners(){
181   for (xm=[0,1]) {
182     mirror([xm,0,0]) 
183     translate((hsz - cnr_rad) * [1,1])
184     intersection(){
185       rotate_extrude(convexity=10)
186         translate([-cnr_rad,0])
187         children();
188       translate([0,0,-250])
189         cube([50,50,500]);
190     }
191   }
192 }
193
194 module Box(){
195   /// corners, and front and back of base
196   for (ym=[0,1]) mirror([0,ym,0]) {
197     AtTwoCorners(){
198       UsualProfile();
199     }
200     hull() AtTwoCorners(){
201       upp_app_Vars(bevel){
202         polygon([ $xppI,
203                   $xppF,
204                   $xppF + [0.1, 0],
205                   $xppI + [0.1, 0]
206                   ]);
207       }
208     }
209   }
210
211   // side walls and base
212   SWalls(yw6 , yw4 , bevel  ) { UsualProfile();      BaseProfile(); }
213   SWalls(yw5 , yw4 , a_bevel) { AnchorWallProfile(); BaseProfile(); }
214   SWalls(yw5 , yw12, a_bevel) { NearAnchorProfile(); BaseProfile(); }
215   SWalls(yw3 , yw2 , a_bevel) { AnchorProfile();     BaseProfile(); }
216   SWalls(yw11, yw12, a_bevel) { AnchorWallProfile(); BaseProfile(); }
217   SWalls(yw11, yw13, bevel  ) { UsualProfile();      BaseProfile(); }
218   SWalls(yw1,  yw10, a_bevel) { WebProfile(); SomeBaseProfile($gppS, $xppF); }
219
220   // front and rear walls
221   rotate([0,0,90]) SWalls(yw6, yw13, bevel) UsualProfile();
222 }
223
224 module KsafeBase(){
225   cut = main_sz + 20;
226
227   difference(){
228     Box();
229
230     // bolt holes
231     translate([0,0, -bolt_above -0.5 * bolthole_height])
232       cube(center=true, [ cut, bolthole_width, bolthole_height ]);
233
234     // string slot
235     translate([ -cut,
236                 -(bolthole_width/2 + bolthole_rhs),
237                 1 ])
238       mirror([0,1,0]) mirror([0,0,1])
239       cube([ cut*2,
240              string_slot,
241              lidinner_thick_allow + string_depth + 1 ]);
242   }
243 }
244
245 module DemoProfiles(){
246   translate([0,0,-2]) color("yellow") AnchorWallProfile();
247   color("red") AnchorProfile();
248   translate([0,0,2]) color("black") NearAnchorProfile();
249   translate([0,0,4]) color("blue") UsualProfile();
250   translate([0,0,-4]) color("pink") WebProfile();
251 }
252
253 //DemoProfiles();
254 //Box();
255 KsafeBase();