chiark / gitweb /
lock-inframe-bracket: DividePlan on its way
[reprap-play.git] / lock-inframe-bracket.scad
1 // -*- C -*-
2
3 // use shell thickness 1.50
4 // use fill density 40%
5
6 include <funcs.scad>
7
8 tube_dia = 27.5 + 1.625;
9 lock_w = 42.5 + 0.5;
10 lock_d = 28.0 + 0.5;
11 main_h = 45.0;
12 backflange_d = 12;
13 lockshaft_dia = 14.35;
14
15 cliprecess_h = 16;
16 total_h = 45;
17
18 back_gap = 10.5;
19 main_th = 3.25;
20 tube_th = 3.75;
21
22 midweb_d = 3;
23 clip_th = 3.5;
24 clip_gap = 2.5;
25 clip_d = 22.0;
26
27 mountscrew_dia = 4 + 0.5;
28 clipbolt_dia = 5 + 0.6;
29
30 backflange_th = 4.5;
31
32 $fn=50;
33
34 join_cr = 9;
35
36 tube_rear_extra_th = 1;
37
38 divide_shaft_w = 1.75;
39 divide_shaft_l = 1.5;
40 divide_head_dx = 1.75;
41 divide_head_th = 1.5;
42 divide_gap = 0.50;
43 divide_heads = 2;
44
45 divide_angle = 26;
46 divide_fudge_r = 4.75;
47 divide_around = 3.5;
48
49 // calculated
50
51 lockshaft_r = [1, 1] * lockshaft_dia / 2;
52 front_th = main_th;
53
54 tube_or = tube_dia/2 + tube_th;
55 back_ohw = back_gap/2 + backflange_th;
56 backflange_ymin = tube_or+backflange_d;
57
58 lock_0y = tube_dia/2 + lock_d/2 + midweb_d;
59 lock_0x = lock_w/2 - lock_d/2;
60 lock_0 = [lock_0x,lock_0y];
61
62 lock_or = [lock_w, lock_d]/2 + [front_th,front_th];
63
64 module oval(sz){ // sz[0] > sz[1]
65   xr = sz[0];
66   yr = sz[1];
67   hull(){
68     for (sx=[-1,+1]) {
69       translate([sx * (xr-yr), 0])
70         circle(r=yr);
71     }
72   }
73 }
74
75 module JoinCircs(jr){
76   // http://mathworld.wolfram.com/Circle-CircleIntersection.html
77   R = tube_or + join_cr;
78   r = lock_or[1] + join_cr;
79   d = dist2d( [0,0], lock_0 );
80   x = (d*d - r*r + R*R) / (2*d);
81   y = sqrt( R*R - x*x );
82
83   echo(lock_0x, lock_0y, R,r, d, x,y);
84
85   for (m=[0,1]) {
86     mirror([m,0]) {
87       rotate(atan2(lock_0y, lock_0x)) {
88         translate([x,-y])
89           circle(r= jr);
90       }
91     }
92   }
93 }
94
95 module DividePlan(xl=10){
96   w = divide_shaft_w;
97   g = divide_gap;
98   l = divide_shaft_l + g;
99   t = divide_head_th + g;
100   dx = divide_head_dx;
101   for (m=[0,1]) mirror([m,0]) {
102     translate([w, 0]) square([xl, g]);
103     for (i=[0:divide_heads-1]) {
104       translate([w, i*(l + t)]) {
105         translate([0, 0]) square([g, l + g]);
106         translate([0, l]) square([divide_head_dx + g, g]);
107         translate([dx, l]) square([g, t + g]);
108         translate([0, l + t])
109           square([divide_head_dx + g, g]);
110       }
111     }
112     translate([-0.1, (l + t) * divide_heads])
113       square([w + g, g]);
114   }
115 }
116
117 module DividePlanInPlace(xl=10){
118   rotate([0,0, -divide_angle])
119     translate([ -tube_dia/2 -tube_th/2 - divide_fudge_r, 0])
120     DividePlan(xl);
121 }
122
123 module MainPlan(){
124   difference(){
125     union(){
126       difference(){
127         union(){
128           hull(){
129             for (t=[0, tube_rear_extra_th])
130               translate([0, -t])
131                 circle(r = tube_or);
132           }
133           translate([-back_ohw,0]) mirror([0,1])
134             square([back_ohw*2, backflange_ymin]);
135
136           translate([0, lock_0y]){
137             oval(lock_or);
138           }
139
140           hull(){
141             JoinCircs(0.01);
142             polygon([[0,0], lock_0, [-lock_0[0], lock_0[1]]]);
143           }
144         }
145
146         translate([-back_gap/2,1]) mirror([0,1])
147           square([back_gap, backflange_ymin+2]);
148
149         JoinCircs(join_cr);
150       }
151
152       hull(){
153         minkowski(){
154           DividePlanInPlace(0.1);
155           circle(divide_around);
156         }
157       }
158     }
159     translate([0, lock_0y]){
160       oval([lock_w/2, lock_d/2]);
161     }
162
163     circle(r = tube_dia/2);
164
165     DividePlanInPlace();
166   }
167 }
168
169 lockshaft_or = lockshaft_r + [clip_th,clip_th];
170 cliprecess_ymax = cliprecess_h - lockshaft_r[1];
171 clip_ymin = cliprecess_ymax - total_h;
172 clip_ogap = clip_gap + clip_th*2;
173
174 module ClipElevationPositive(){
175   hull(){
176     oval(lockshaft_or);
177     translate([0, -lockshaft_or[1] * sqrt(2)])
178       square(center=true, 0.5);
179   }
180   translate([-lockshaft_or[0], 0])
181     square([lockshaft_or[0]*2, cliprecess_ymax]);
182   translate([-clip_ogap/2, 0]) mirror([0,1]) square([clip_ogap, -clip_ymin]);
183 }
184
185 module ClipElevationNegative(){
186   hull(){
187     for (y=[0, cliprecess_ymax+1])
188       translate([0, y])
189         oval(lockshaft_r);
190   }
191   translate([-clip_gap/2, 1]) mirror([0,1]) square([clip_gap, 2-clip_ymin]);
192 }
193
194 module ClipElevation(){
195   difference(){
196     ClipElevationPositive(1);
197     ClipElevationNegative(0);
198   }
199 }
200
201 module ExtrudeClipElevation(extra=0){
202   translate([0,
203              lock_0y + lock_d/2 + clip_d + extra,
204              -clip_ymin])
205     rotate([90,0,0])
206     linear_extrude(height= clip_d + extra*2, convexity=100)
207     children(0);
208 }
209
210 module ThroughHole(r, y, z) {
211   translate([-50, y, z])
212     rotate([0, 90, 0])
213     cylinder(r=r, h=100, $fn=20);
214 }
215
216 module ThroughHoles(){
217   for (z=[ 1/4, 3/4 ]) {
218     ThroughHole( mountscrew_dia/2,
219                  -tube_or -0.5*backflange_d,
220                  total_h * z );
221   }
222
223   ThroughHole( clipbolt_dia/2,
224                lock_0y + lock_d/2 + clip_d/2 + front_th/2,
225                total_h - cliprecess_h - clip_th - clip_d/2 );
226 }
227
228 module MainPositive(){
229   difference(){
230     union(){
231       linear_extrude(height=total_h, convexity=100) MainPlan();
232       ExtrudeClipElevation() ClipElevationPositive();
233     }
234     ExtrudeClipElevation(1) ClipElevationNegative();
235   }
236 }
237
238 module Bracket(){ //// toplevel
239   difference(){
240     MainPositive();
241     ThroughHoles();
242   }
243 }
244
245 module TestTopEdge(){ //// toplevel
246   intersection(){
247     translate([0,0, -total_h])
248       translate([0,0, 4])
249       Bracket();
250     translate([-200,-200,0])
251       cube([400,400,100]);
252   }
253 }
254
255 module TestClipBoltHole(){ //// toplevel
256   intersection(){
257     union(){
258       translate([0, 0, -5])
259         Bracket();
260       translate([-4, lock_0y + lock_d/2 + 1, 0])
261         cube([8, 4, 1.5]);
262     }
263     translate([-200, lock_0y + lock_d/2 + 0.1])
264       cube([400, 400, total_h-20]);
265   }
266 }
267
268 //MainPlan();
269 //ClipElevationPositive();
270 //ClipElevation();
271 //MainPositive();
272 //%ThroughHoles();
273 //TestTopEdge();
274 //TestClipBoltHole();
275 //DividePlan();
276
277 Bracket();
278