chiark / gitweb /
4d9701fc3f7e408c8960475585a2c84d6286c602
[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 thumbslot_depth = 5.0;
27 thumbslot_width = 15.0;
28 thumbslot_between = 10;
29
30 // ----- calculated -----
31
32 hsz = main_sz/2;
33
34 gppA = [0,0];
35 gppB = gppA - [ wall_thick, 0 ];
36
37 gppL = [ gppB[0], -(lidinner_thick_allow + space + base_thick) ];
38
39 yw1 = -web_thick/2;
40 yw2 = yw1 - bolthole_rhs;
41 yw3 = yw2 - anchor_thick;
42 yw4 = yw3 - anchor_wall_space;
43 yw5 = yw4 - wall_thick;
44 yw6 = -(hsz - cnr_rad + 0.1);
45
46 yw10 = web_thick/2;
47 yw11 = yw2 + anchor_wall_space;
48 yw12 = yw11 + wall_thick;
49 yw13 = -yw6;
50
51 // anchor
52
53 anchor_b = anchor_thick + anchor_rad;
54 appM = gppL + anchor_b * [1,1];
55
56 a_bevel = 2 * anchor_b * (1 + sqrt(0.5));
57
58 module upp_app_Vars(t_bevel){
59   $xppE = gppL + t_bevel * [0,1];
60   $xppF = gppL + t_bevel * [1,0];
61
62   $xppJ = $xppE + wall_thick * [ 1, tan(22.5) ];
63   $xppI = $xppF + base_thick * [ tan(22.5), 1 ];
64
65   // must pass a_bevel for t_bevel for these to be valid
66   $gppP = gppA + [0,-1] * lidinner_thick_allow;
67   $gppQ = $gppP + [1,-1] * web_height;
68   $gppR = $xppJ + [ 1, tan(22.5) ] * web_height;
69   $gppS = $xppI + [ tan(22.5), 1 ] * web_height;
70   $gppT = [ $gppQ[0], $xppE[1] ];
71
72   children();
73 }
74
75 module upp_app_Profile(){
76   polygon([ gppA,
77             gppB,
78             $xppE,
79             $xppF,
80             $xppF + [1,0],
81             $xppI + [1,0],
82             $xppJ ],
83           convexity=10);
84 }
85
86
87 module UsualProfile(){
88   upp_app_Vars(bevel) upp_app_Profile();
89 }
90
91 module NearAnchorProfile(){
92   upp_app_Vars(a_bevel) upp_app_Profile();
93 }
94
95 module AnchorProfile(){
96   upp_app_Vars(a_bevel) {
97
98     upp_app_Profile();
99
100     difference(){
101       hull(){
102         polygon([ $xppE,
103                   $xppF,
104                   $xppF + [0,1],
105                   $xppE + [1,0] ],
106           convexity=10);
107         translate(appM) circle(r= anchor_b);
108       }
109       translate(appM) circle(r= anchor_rad);
110     }
111   }
112 }
113
114 module AnchorWallProfile(){
115   UsualProfile();
116   NearAnchorProfile();
117   hull(){
118     for (bev = [bevel, a_bevel]) {
119       upp_app_Vars(bev) {
120         polygon([ $xppE,
121                   $xppF,
122                   $xppI,
123                   $xppJ ],
124           convexity=10);
125       }
126     }
127   }
128 }
129
130 module WebProfile(){
131   upp_app_Vars(a_bevel){
132     if ($gppR[1] <= $gppP[1]) {
133       polygon([ $gppP,
134                 $xppE,
135                 $gppT,
136                 $gppQ ]);
137       polygon([ $gppP,
138                 $xppE,
139                 $xppF,
140                 $gppS,
141                 $gppR ],
142           convexity=10);
143     } else {
144       polygon([ $gppP,
145                 $xppE,
146                 $xppF,
147                 $gppS,
148                 $gppP + web_height * [1,0] ],
149           convexity=10);
150     }
151     polygon([ $gppS,
152               $xppF,
153               $xppF + [1,0],
154               $gppS + [1,0] ],
155           convexity=10);
156   }
157 }
158
159 module SomeBaseProfile(I, F){
160   polygon([ I,
161             F,
162             [ hsz+1, F[1] ],
163             [ hsz+1, I[1] ] ]);
164 }
165
166 module BaseProfile(){
167   SomeBaseProfile($xppI, $xppF);
168 }
169
170 module SWalls(ymin, ymax, t_bevel) {
171   upp_app_Vars(t_bevel) {
172     translate([0,ymin,0])
173       mirror([0,1,0])
174       rotate([90,0,0])
175       linear_extrude(height= ymax-ymin, convexity=10)
176       for (xm=[0,1])
177         mirror([xm,0])
178           translate([-hsz, 0])
179             children();
180   }
181 }
182
183 module AtTwoCorners(){
184   for (xm=[0,1]) {
185     mirror([xm,0,0]) 
186     translate((hsz - cnr_rad) * [1,1])
187     intersection(){
188       rotate_extrude(convexity=10)
189         translate([-cnr_rad,0])
190         children();
191       translate([0,0,-250])
192         cube([50,50,500]);
193     }
194   }
195 }
196
197 module Box(){
198   /// corners, and front and back of base
199   for (ym=[0,1]) mirror([0,ym,0]) {
200     AtTwoCorners(){
201       UsualProfile();
202     }
203     hull() AtTwoCorners(){
204       upp_app_Vars(bevel){
205         polygon([ $xppI,
206                   $xppF,
207                   $xppF + [0.1, 0],
208                   $xppI + [0.1, 0]
209                   ]);
210       }
211     }
212   }
213
214   // side walls and base
215   SWalls(yw6 , yw4 , bevel  ) { UsualProfile();      BaseProfile(); }
216   SWalls(yw5 , yw4 , a_bevel) { AnchorWallProfile(); BaseProfile(); }
217   SWalls(yw5 , yw12, a_bevel) { NearAnchorProfile(); BaseProfile(); }
218   SWalls(yw3 , yw2 , a_bevel) { AnchorProfile();     BaseProfile(); }
219   SWalls(yw11, yw12, a_bevel) { AnchorWallProfile(); BaseProfile(); }
220   SWalls(yw11, yw13, bevel  ) { UsualProfile();      BaseProfile(); }
221   SWalls(yw1,  yw10, a_bevel) { WebProfile(); SomeBaseProfile($gppS, $xppF); }
222
223   // front and rear walls
224   rotate([0,0,90]) SWalls(yw6, yw13, bevel) UsualProfile();
225 }
226
227 module KsafeBase(){ ////toplevel
228   cut = main_sz + 20;
229
230   difference(){
231     Box();
232
233     // bolt holes
234     translate([0,0, -bolt_above -0.5 * bolthole_height])
235       cube(center=true, [ cut, bolthole_width, bolthole_height ]);
236
237     // string slot
238     translate([ -cut,
239                 -(bolthole_width/2 + bolthole_rhs),
240                 1 ])
241       mirror([0,1,0]) mirror([0,0,1])
242       cube([ cut*2,
243              string_slot,
244              lidinner_thick_allow + string_depth + 1 ]);
245
246     // thumb slots
247     for (mx=[0,1]) mirror([mx,0,0]) {
248       translate([ thumbslot_between/2,
249                   0,
250                   -thumbslot_depth ])
251         cube([ thumbslot_width,
252                cut,
253                thumbslot_depth+1 ]);
254     }
255   }
256 }
257
258 module DemoProfiles(){
259   translate([0,0,-2]) color("yellow") AnchorWallProfile();
260   color("red") AnchorProfile();
261   translate([0,0,2]) color("black") NearAnchorProfile();
262   translate([0,0,4]) color("blue") UsualProfile();
263   translate([0,0,-4]) color("pink") WebProfile();
264 }
265
266 module RimTest(){ ////toplevel
267   intersection(){
268     Box();
269     cube(center=true, [ main_sz*2, main_sz*2,
270                         2.5 ]);
271   }
272 }
273
274 module BoltTest(){ ////toplevel
275   dy = 0.5 * (bolthole_width+4);
276   intersection(){
277     KsafeBase();
278     translate([ 0, -dy, -(bolt_above + bolthole_height + 1) ])
279       cube([ main_sz, dy*2, 50 ]);
280   }
281 }
282
283 //DemoProfiles();
284 //Box();
285 //KsafeBase();
286 //RimTest();