aboutsummaryrefslogtreecommitdiff
path: root/bitstorage.scad
blob: aa443dfa28b8472424c0e706afee118f2c6c723a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use <gridfinity.scad>

mm_1_4_inch = 6.35;

diam = mm_1_4_inch;
wall = 1.5;

bit_depth = 5;

// size in GF units
ux = 2;
uy = 2;

function r_from_d(d) = d/2 / sin(60);
function staggered_offset(d, w) = r_from_d(d)*1.5 + sin(60) * w;

function hc_max_y(max_y, d, w) = floor( max_y / (diam + wall) - 1 );
function hc_max_x(max_x, d, w) = floor( (max_x - r_from_d(d)/2 ) / (staggered_offset(d,w)) - 1 );

// d is from flat side to flat side -> wrench size
module hexagon(d) {
  l = r_from_d(d);
  translate([l,l]) circle(l, $fn=6);
}

// d = wrench size, w = wall
module honeycomb(cnt_x, cnt_y, d, w) {
  // we want wall distance also at a 60deg angle.
  x_offset = staggered_offset(d,w);

  for (ix = [0:cnt_x]) {
    // every second row is offset
    offs = ix%2 == 1 ? (d + w) / 2 : 0;
    x = x_offset * ix;

    for (iy = [0 : cnt_y - ix%2]) {
      y = iy * (d + w) + offs;
      translate([x,y]) hexagon(d);
    }
  }
}

module honeycomb_fit(x, y, d, w) {
  honeycomb(hc_max_x(x,d,w), hc_max_y(y,d,w), d, w);
}

module honeycomb_fit_center(x, y, d, w) {
  // mostly educated guessing, certainly not perfectly center
  offs_y = (y - ((hc_max_y(y, d, w) + 1) * (d+w))) /2;
  offs_x = (x - (hc_max_x(x, d, w) + 1) * staggered_offset(d, w) - r_from_d(d)/2) / 2;

  translate([offs_x, offs_y]) honeycomb_fit(x,y,d,w);
}

difference() {
  gridfinity(ux, uy, 3, lip=true, magnets=false, fill = false, bottom_height = bit_depth);
  translate(gf_inner_origin()) translate(gf_top_vec(0))
    linear_extrude(bit_depth + 0.01)
      honeycomb_fit_center(gf_inner(ux), gf_inner(uy), diam,wall);
}