chiark / gitweb /
knifeblock: Holes refactor: move holeoffx/y into HexGrid (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 HexGrid(imin,imax,jmin,jmax) {
228   for (i=[imin:imax]) {
229     for (j=[jmin:jmax]) {
230       translate([(j * sqrt(3) + holeoffx) * holepitch,
231                  (i +     0.5 + holeoffy) * holepitch,
232                  0]) {
233         child();
234         translate([sqrt(3)/2 * holepitch, -0.5 * holepitch, 0])
235           child();
236       }
237     }
238   }
239 }
240
241 module Hole(){
242   cylinder(r=holesize/2, h=40, $fn=40);
243 }
244
245 module Holes(){
246   imax = ceil(coverlonglen / holepitch);
247   echo("Holes Y count ", imax);
248   jmin = ceil((maxx-minx)/(sqrt(3)*holepitch));
249   echo("Holes X count 2 x", jmin);
250   intersection(){
251     translate([0, 0, -20])
252       HexGrid(0,imax,-jmin,2)
253       Hole();
254     HolesScope();
255   }
256 }
257
258 module CoverCover(){
259   difference(){
260     CoverTemplate();
261     Holes();
262   }
263 }
264
265 module Cover(){
266   difference(){
267     union(){
268       CoverCover();
269       AtSides() { CoverSide(covershortlen); CoverSide(coverlonglen); }
270     }
271     AtSides() { CoverPegSlot(); CoverPegSlot(); }
272   }
273 }
274
275 module CoverAligned(){
276   translate([0,-front,-height])
277     rotate([-90,0,0])
278     Cover();
279 }
280
281 module DemoPeg(){
282   translate([recessblockwidth/2, pegrecess, -height])
283     Peg();
284 }
285
286 module Demo(){ ////toplevel
287   %Block();
288   DoKnives();
289   color([0,0,1]) CoverAligned();
290   color([1,0,0]) AtSides() { DemoPeg(); DemoPeg(); }
291 }
292
293 module Pegs(){ ////toplevel
294   Peg();
295   translate([-peghead-3, 0,0]) Peg();
296 }
297
298 module CoverParts(){ ////toplevel
299   Cover();
300   translate([0, coverlonglen, pegheight/2-pegslopv])
301     Pegs();
302 }
303
304 //Block();
305 //Demo();
306 //Cover();
307 //CoverParts();
308 //Peg();
309 //Cover();
310 //Holes();
311 //%CoverTemplate();
312 //Pegs();