bakje/gridfinity.scad
2025-01-28 13:05:52 +01:00

267 lines
7.7 KiB
OpenSCAD

$fn=50;
HIEGHT = 3;
SLOT = 42;
WALL_THINKNESS = 1;
SOCKET_TOLLARANCE = 0.25;
module square_rounded(size1, size2, r1, r2, h) {
if (is_num(size1)) {
size1 = [size1, size1];
size2 = [size2, size2];
square_rounded(size1, size2, r1, r2, h);
}
else
{
union() {
difference() {
translate([0, 0, h/2]) {
cube([size1[0]-r1*2, size2[1], h], center=true);
cube([size2[0], size1[1]-r1*2, h], center=true);
}
for(r=[
[ 0, size1[0], size1[1]],
[ 90, size1[1], size1[0]],
[180, size1[0], size1[1]],
[-90, size1[1], size1[0]]
])
rotate([0, 0, r[0]])
translate([-r[1]/2, r[2]/2, 0])
rotate([-45, 0, 0])
cube([r[1], 2*h, 2*h]);
}
for(r=[
[ 0, size1[0], size1[1]],
[ 90, size1[1], size1[0]],
[180, size1[0], size1[1]],
[-90, size1[1], size1[0]]
])
rotate([0, 0, r[0]])
translate([r[1]/2-r1, r[2]/2-r1])
cylinder(h=h, r1=r1, r2=r2);
}
}
}
module gf_bottom() {
union() {
square_rounded(size1=35.6, size2=37.2, r1=0.8, r2=1.6, h=0.8+0.001);
translate([0, 0, 0.8])
square_rounded(size1=37.2, size2=37.2, r1=1.6, r2=1.6, h=1.8+0.001);
translate([0, 0, 2.6])
square_rounded(size1=37.2, size2=41.5, r1=1.6, r2=3.75, h=2.15+0.001);
}
}
module gf_inside_cut_top(size, fill=false) {
hieght_mm = size[2]*7+5;
add = [(size[0]-1) * 42, (size[1]-1) * 42];
t = WALL_THINKNESS;
a = t*sin(45);
b = t*tan(22.5);
t2 = SOCKET_TOLLARANCE;
a2 = t2*sin(45);
b2 = t2*tan(22.5);
c2 = t2/sin(45);
union() {
bot_l2_h = (4.75)+b;
bot_l2_w = (41.5)-2*t;
bot_l2_r = (3.75)-t;
top_l0_h = hieght_mm-c2;
top_l0_w = (41.5);
top_l0_r = (3.75);
top_l1_hd = (2.15)-c2+b2; top_l1_h = top_l0_h-top_l1_hd;
top_l1_w = (37.2)+t2*2;
top_l1_r = (1.6)+t2;
top_l2_hd = (1.8)-b2; top_l2_h = top_l1_h-top_l2_hd;
top_l2_w = (37.2)+t2*2;
top_l2_r = (1.6)+t2;
top_l3_hd = (bot_l2_w-top_l2_w)/2; top_l3_h = top_l2_h-top_l3_hd;
top_l3_w = bot_l2_w;
top_l3_r = bot_l2_r;
top_l3f_hd = (0.7); top_l3f_h = top_l2_h-top_l3f_hd;
top_l3f_w = top_l2_w-top_l3f_hd*2;
top_l3f_r = top_l2_r-top_l3f_hd;
// bottom layer 2 - top layer 3
if (!fill)
translate([0, 0, bot_l2_h])
square_rounded(size1=[add[0]+bot_l2_w,add[1]+bot_l2_w], size2=[add[0]+top_l3_w,add[1]+top_l3_w], r1=bot_l2_r, r2=top_l3_r, h=top_l3_h-bot_l2_h+0.001);
// top layer 3-0
if (!fill)
translate([0, 0, top_l3_h+top_l3_hd+0.001])
rotate([180, 0])
square_rounded(size1=[add[0]+top_l2_w,add[1]+top_l2_w], size2=[add[0]+top_l3_w,add[1]+top_l3_w], r1=top_l2_r, r2=top_l3_r, h=top_l3_hd+0.001);
if (fill)
translate([0, 0, top_l3f_h])
square_rounded(size1=[add[0]+top_l3f_w,add[1]+top_l3f_w], size2=[add[0]+top_l2_w,add[1]+top_l2_w], r1=top_l3f_r, r2=top_l2_r, h=top_l3f_hd+0.001);
// top layer 2-1 (top flat)
translate([0, 0, top_l2_h])
square_rounded(size1=[add[0]+top_l2_w,add[1]+top_l2_w], size2=[add[0]+top_l1_w,add[1]+top_l1_w], r1=top_l2_r, r2=top_l1_r, h=top_l2_hd+0.001);
// top layer 1-0 (top chan l)
translate([0, 0, top_l1_h])
square_rounded(size1=[add[0]+top_l1_w,add[1]+top_l1_w], size2=[add[0]+top_l0_w,add[1]+top_l0_w], r1=top_l1_r, r2=top_l0_r, h=top_l1_hd+0.001);
// something else
translate([-size[0]*21, -size[1]*21, top_l0_h])
cube([size[0]*42, size[1]*42, hieght_mm-top_l0_h+1]);
}
}
module gf_inside_cut_bot(size) {
hieght_mm = size[2]*7+5;
t = WALL_THINKNESS;
a = t*sin(45);
b = t*tan(22.5);
t2 = SOCKET_TOLLARANCE;
a2 = t2*sin(45);
b2 = t2*tan(22.5);
c2 = t2/sin(45);
union() {
bot_l0_h = t;
bot_l0_w = (37.2)-2*a-((2.6)+a-t)*2;
bot_l0_r = (1.6)-a;
bot_l1_h = (2.6)+a; bot_l1_hd = bot_l1_h-bot_l0_h;
bot_l1_w = (37.2)-2*a;
bot_l1_r = (1.6)-a;
bot_l2_h = (4.75)+b; bot_l2_hd = bot_l2_h-bot_l1_h;
bot_l2_w = (41.5)-2*t;
bot_l2_r = (3.75)-t;
// bottom layer 0-1 (bott chan s, bot flat)
translate([0, 0, bot_l1_h+0.001])
rotate([180,0,0])
linear_extrude(height = bot_l1_hd, scale = bot_l0_w/bot_l1_w)
translate([-(bot_l1_w/2-bot_l1_r), -(bot_l1_w/2-bot_l1_r)])
minkowski() {
square([bot_l1_w-bot_l1_r*2, bot_l1_w-bot_l1_r*2]);
circle(r=bot_l1_r);
}
// bottom layer 1-2 (bot chan l)
translate([0, 0, bot_l1_h])
square_rounded(size1=bot_l1_w, size2=bot_l2_w, r1=bot_l1_r, r2=bot_l2_r, h=bot_l2_hd+0.001);
}
}
GF_BAKJE_MODE_DEFALT=0;
GF_BAKJE_MODE_DEEP=1;
GF_BAKJE_MODE_FILLED=2;
GF_BAKJE_MODE_PARFILL=3;
module gf_bakje(size=[1,1,4], mode=GF_BAKJE_MODE_DEFALT, fill_dis=0) {
hieght_mm = size[2]*7+5;
intersection() {
difference() {
union() {
difference() {
union() {
translate(-[size[0]-1,size[1]-1]*21)
for (x = [0:size[0]-1])
for (y = [0:size[1]-1])
translate([x*42, y*42])
gf_bottom();
translate([-size[0]*21+0.25+3.75, -size[1]*21+0.25+3.75, 4.75])
linear_extrude(hieght_mm-4.75)
minkowski() {
square([size[0]*42-0.5-3.75*2, size[1]*42-0.5-3.75*2]);
circle(r=3.75);
}
}
gf_inside_cut_top(size, fill=(mode==GF_BAKJE_MODE_FILLED));
if (mode == GF_BAKJE_MODE_DEEP) {
translate(-[size[0]-1,size[1]-1]*21)
for (x = [0:size[0]-1])
for (y = [0:size[1]-1])
translate([x*42, y*42])
gf_inside_cut_bot();
}
}
if (mode == GF_BAKJE_MODE_DEEP) {
// inside point for grid shape
union() {
translate(-[size[0],size[1]]*21)
for (x = [1:size[0]-1])
translate([x*42, size[1]*42/2, 5])
rotate([0, 45, 0])
cube([2, size[1]*42-1, 2], center=true);
translate(-[size[0],size[1]]*21)
for (y = [1:size[1]-1])
translate([size[0]*42/2, y*42, 5])
rotate([45, 0, 0])
cube([size[0]*42-1, 2, 2], center=true);
// corner rounding
translate([-size[0]*21,-size[1]*21])
for (x = [0:size[0]])
for (y = [0:size[1]])
translate([x*42, y*42, 5.75])
difference() {
cube([3.75*2+.5, 3.75*2+.5, 1.3], center=true);
for (r = [0:90:360])
rotate([0, 0, r])
translate([3.75+.25, 3.75+.25, -1.3/2-0.001])
cylinder(h=1.302, r1=(3.65)-WALL_THINKNESS, r2=(3.65)-WALL_THINKNESS+1.3);
}
}
}
if (mode == GF_BAKJE_MODE_DEFALT || mode == GF_BAKJE_MODE_PARFILL)
translate([0, 0, (mode == GF_BAKJE_MODE_PARFILL) ? fill_dis/2+5.5 : 5.5])
cube([
size[0]*42-0.5-WALL_THINKNESS*2,
size[1]*42-0.5-WALL_THINKNESS*2,
(mode == GF_BAKJE_MODE_PARFILL) ? fill_dis : 1
], center=true);
}
// bottom cut for git shape
translate(-[size[0],size[1]]*21)
for (x = [1:size[0]-1])
translate([x*42, size[1]*42/2, 3.59])
rotate([0, 45, 0])
cube([2, size[1]*42-1, 2], center=true);
translate(-[size[0],size[1]]*21)
for (y = [1:size[1]-1])
translate([size[0]*42/2, y*42, 3.59])
rotate([45, 0, 0])
cube([size[0]*42-1, 2, 2], center=true);
// bottom cut for intersections
translate([-size[0]*21,-size[1]*21])
for (x = [0:size[0]])
for (y = [0:size[1]])
translate([x*42, y*42, 4.6])
difference() {
cube([3.75*2+.5, 3.75*2+.5, 0.8], center=true);
for (r = [0:90:360])
rotate([0, 0, r])
translate([3.75+.25, 3.75+.25, -0.401])
cylinder(h=0.804, r1=3.7-0.5, r2=3.7+0.3);
}
}
square_rounded(size1 = [size[0]*42-.5, size[1]*42-.5], size2 = [size[0]*42-.5, size[1]*42-.5], r1 = 3.75, r2 = 3.75, h = hieght_mm);
}
}
module gf_socket_cut() {
t = 0.25;
a = sin(45)*t;
b = a*tan(22.5);
c = t/sin(45);
translate([0, 0, -a])
union() {
square_rounded(size1=35.6+a*2, size2=37.2+2*t, r1=0.8+a, r2=1.6+t, h=0.8+b+0.001);
translate([0, 0, 0.8+b])
square_rounded(size1=37.2+2*t, size2=37.2+2*t, r1=1.6+t, r2=1.6+t, h=1.8+b+0.001);
translate([0, 0, 2.6+b])
square_rounded(size1=37.2+2*t, size2=41.5+2*c, r1=1.6+t, r2=3.75+c, h=2.15+a-b-0.001);
}
}
if (RENDER_GF_BASE) {
gf_bakje([WIDTH, DEPTH, HIEGHT], mode=MODE);
}
gf_bakje([2, 2, 5], mode=1);