chiark / gitweb /
knifeblock: Holes refactor: fold in HoleRow (nfc)
[reprap-play.git] / knifeblock.scad
1 // -*- C -*-
2
3 // properties of the knives
4 nknives = 3;
5 widths = [15.5, 15.8, 19.0];
6 handlelenbase = 75;
7 handlelendelta = [-15, 0, 10];
8 locations = [-35, 0, 37];
9 bladew = 5; // 2.5
10 maxhandledepth = 45;
11
12 templatescale = 27.2 / 19.6;
13
14 coverlonglen = 120; // xxx
15 covershortlen = 70; // xxx
16
17 // other tuneables
18 front = 5;
19 back = 5;
20 height = 50;
21 minsidein = 4;
22 minsideout = 4;
23
24 frontbackslop = 0.25;
25
26 knifewidthslop = 2.0;
27
28 screwbackdepth = 6.0 - 1.0;
29 screwdia =       4.0 + 0.5;
30 screwcsinkdia =  9.8 + 1.0;
31
32 screwabove = 15;
33
34 coverthick = 2.4;
35 coverside = coverthick;
36
37 covertopwing = 15;
38 covertopwingbase = 20;
39 coveredge = 3;
40
41 holesize = 12.5;
42 holestrut = 7;
43 holeedge = 4;
44
45 holeoffx = 0.33;
46 holeoffy = 0.23;
47
48 pegstem = 3.5;
49 peghead = 10;
50 pegstemheight = 2;
51 pegheight = 9;
52 peglen = 12;
53
54 recessblockwidth = peghead + pegstem*3;
55 recessblockheight = peglen/2 + pegstem*1.5;
56
57 pegsloph = 0.5;
58 pegslopv = 0.5;
59 pegslopl = 0.5;
60
61 pegdepthproportion = 0.80;
62
63 // computed
64
65 function width(k) = widths[k] + knifewidthslop;
66
67 side = minsidein + screwcsinkdia + minsideout;
68 totaldepth = front + maxhandledepth + back;
69
70 minkx = locations[0] -         width(0)        /2;
71 maxkx = locations[nknives-1] + width(nknives-1)/2;
72
73 minx = minkx - side;
74 maxx = maxkx + side;
75
76 holepitch = holesize+holestrut;
77
78 pegrecess = pegdepthproportion*totaldepth - 0.5*peglen;
79
80 module ImportTemplate(w,k,t) {
81   fn = str("knifeblock-knives-t",k,t,".dxf");
82   echo(fn);
83   translate([0,0, -w/2])
84     linear_extrude(height=w)
85     scale(templatescale) import(file=fn, convexity=100);
86 }
87
88 module Knife(k){
89   ImportTemplate(bladew, k,"bl");
90   hull(){
91     ImportTemplate(width(k), k,"hl");
92     translate([-100,0,0])
93       ImportTemplate(width(k), k,"hl");
94   }
95 }
96
97 module DoKnife(k){
98   translate([locations[k],0,0]){
99     rotate([0,90,0])
100       translate([-(handlelenbase + handlelendelta[k]),0,0])
101       Knife(k);
102   }
103 }
104
105 module DoKnives(){
106   for (k=[0:nknives-1])
107     DoKnife(k);
108 }
109
110 module ScrewHole(){
111   translate([0,-50,0])
112     rotate([-90,0,0])
113     cylinder(r=screwdia/2, h=150, $fn=40);
114   translate([0, totaldepth-front - screwbackdepth, 0])
115     rotate([90,0,0])
116     cylinder(r=screwcsinkdia/2 / (sqrt(3)/2), h=100, $fn=6);
117 }
118
119 module PegTemplate(apex){
120   for (mx=[0,1]) for (my=[0,1]) {
121       mirror([mx,0,0]) mirror([0,my,0])
122         polygon([[-0.1,      -0.1],
123                  [pegstem/2, -0.1],
124                  [pegstem/2, pegstemheight/2],
125                  [peghead/2, pegheight    /2],
126                  [-0.1,      pegheight    /2 + apex]]);
127     }
128 }
129
130 module AtSides(){
131   translate([minx,0,0])                 child(0);
132   translate([maxx,0,0]) mirror([1,0,0]) child(1);
133 }
134
135 module BlockPegSlot(){
136   translate([recessblockwidth/2, pegrecess - peglen, -height]){
137     rotate([-90,0,0]) linear_extrude(height=totaldepth){
138       PegTemplate(peghead/2 * 1.2);
139     }
140   }
141 }
142
143 module Block(){
144   sidemidx = minsideout + screwcsinkdia/2;
145
146   difference(){
147     mirror([0,0,1]) {
148       translate([minx, -front, 0])
149         cube([maxx-minx, totaldepth, height]);
150     }
151     for (x=[minx + sidemidx, maxx - sidemidx]) {
152       translate([x, 0, -screwabove])
153         ScrewHole();
154     }
155     for (yshift=[-1,1])
156       translate([0, yshift * frontbackslop, 0])
157         DoKnives();
158     AtSides() { BlockPegSlot(); BlockPegSlot(); }
159   }
160 }
161
162 module BlockPrint(){ ////toplevel
163   rotate([0,0,90])
164     Block();
165 }
166
167 module CoverTemplate(){
168   linear_extrude(height=coverthick)
169     polygon([[minx, 0],
170              [maxx, 0],
171              [maxx, coverlonglen+0.1],
172              [maxx - coverside, coverlonglen+0.1],
173              [minx, covershortlen+0.1]]);
174 }
175
176 module CoverSide(len){
177   translate([0, 0 ,0]) {
178     rotate([90,0,90])
179       linear_extrude(height=coverside)
180       polygon([[0,                      0],
181                [0,                      totaldepth],
182                [covertopwing,           totaldepth],
183                [covertopwingbase,       coverside + coverthick],
184                [len - covertopwingbase, coverside + coverthick],
185                [len - covertopwing,     totaldepth],
186                [len,                    totaldepth],
187                [len,                    0]]);
188     cube([recessblockwidth, recessblockheight, totaldepth]);
189   }
190 }
191
192 module Peg(){
193   echo("peg angle slope (must be <1)",
194        (peghead-pegstem)/(pegheight-pegstemheight));
195   dx = pegsloph;
196   dy = pegslopv;
197   rotate([90,0,0]) {
198     linear_extrude(height=peglen-pegslopl) {
199       intersection(){
200         translate([-dx,-dy,0]) PegTemplate(0);
201         translate([-dx,+dy,0]) PegTemplate(0);
202         translate([+dx,+dy,0]) PegTemplate(0);
203         translate([+dx,-dy,0]) PegTemplate(0);
204       }
205     }
206   }
207 }
208
209 module CoverPegSlot(coverlen){
210   translate([recessblockwidth/2, 0, -1]){
211     linear_extrude(height= 1 + pegrecess + 0.5*peglen){
212       PegTemplate(0);
213     }
214   }
215 }
216
217 module HolesScope(){
218   intersection_for (dx=[-1,+1]) {
219     intersection_for (dy=[-1,+1]) {
220       translate([dx * holeedge, dy * holeedge, -5])
221         scale([1,1,10])
222         CoverTemplate();
223     }
224   }
225 }
226
227 module Hole(){
228   cylinder(r=holesize/2, h=40, $fn=40);
229 }
230
231 module Holes(){
232   imax = ceil(coverlonglen / holepitch);
233   echo("Holes Y count ", imax);
234   jmin = ceil((maxx-minx)/(sqrt(3)*holepitch));
235   echo("Holes X count 2 x", jmin);
236   intersection(){
237     translate([holeoffx * holepitch, holeoffy * holepitch, 0]) {
238       for (i=[0:imax]) {
239         translate([0, (i+0.5)*holepitch, -20])
240           for (j=[-jmin:2]) {
241             translate([j * sqrt(3) * holepitch, 0, 0]) {
242               Hole();
243               translate([sqrt(3)/2 * holepitch, -0.5 * holepitch, 0])
244                 Hole();
245             }
246           }
247       }
248     }
249     HolesScope();
250   }
251 }
252
253 module CoverCover(){
254   difference(){
255     CoverTemplate();
256     Holes();
257   }
258 }
259
260 module Cover(){
261   difference(){
262     union(){
263       CoverCover();
264       AtSides() { CoverSide(covershortlen); CoverSide(coverlonglen); }
265     }
266     AtSides() { CoverPegSlot(); CoverPegSlot(); }
267   }
268 }
269
270 module CoverAligned(){
271   translate([0,-front,-height])
272     rotate([-90,0,0])
273     Cover();
274 }
275
276 module DemoPeg(){
277   translate([recessblockwidth/2, pegrecess, -height])
278     Peg();
279 }
280
281 module Demo(){ ////toplevel
282   %Block();
283   DoKnives();
284   color([0,0,1]) CoverAligned();
285   color([1,0,0]) AtSides() { DemoPeg(); DemoPeg(); }
286 }
287
288 module Pegs(){ ////toplevel
289   Peg();
290   translate([-peghead-3, 0,0]) Peg();
291 }
292
293 module CoverParts(){ ////toplevel
294   Cover();
295   translate([0, coverlonglen, pegheight/2-pegslopv])
296     Pegs();
297 }
298
299 //Block();
300 //Demo();
301 //Cover();
302 //CoverParts();
303 //Peg();
304 //Cover();
305 //Holes();
306 //%CoverTemplate();
307 //Pegs();