Skip to content

Commit

Permalink
Always auto calculate divisions per grid
Browse files Browse the repository at this point in the history
If someone wants to make custom sized grid bins, they can pass in custom grid_dimensions.
  • Loading branch information
EmperorArthur committed Oct 8, 2024
1 parent efda37f commit d4b5b1c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 43 deletions.
18 changes: 6 additions & 12 deletions gridfinity-rebuilt-bins.scad
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ style_lip = 0; //[0: Regular lip, 1:remove lip subtractively, 2: remove lip and
// scoop weight percentage. 0 disables scoop, 1 is regular scoop. Any real number will scale the scoop.
scoop = 1; //[0:0.1:1]

/* [Base] */
// number of divisions per 1 unit of base along the X axis. (default 1, only use integers. 0 means automatically guess the right division)
div_base_x = 0;
// number of divisions per 1 unit of base along the Y axis. (default 1, only use integers. 0 means automatically guess the right division)
div_base_y = 0;

/* [Base Hole Options] */
// only cut magnet/screw holes at the corners of the bin to save uneccesary print time
only_corners = false;
Expand Down Expand Up @@ -118,7 +112,7 @@ gridfinityInit(gridx, gridy, height(gridz, gridz_define, style_lip, enable_zsnap
cutCylinders(n_divx=cdivx, n_divy=cdivy, cylinder_diameter=cd, cylinder_height=ch, coutout_depth=c_depth, orientation=c_orientation, chamfer=c_chamfer);
}
}
gridfinityBase(gridx, gridy, l_grid, div_base_x, div_base_y, hole_options, only_corners=only_corners, thumbscrew=enable_thumbscrew);
gridfinityBase([gridx, gridy], hole_options=hole_options, only_corners=only_corners, thumbscrew=enable_thumbscrew);
}


Expand All @@ -129,7 +123,7 @@ gridfinityBase(gridx, gridy, l_grid, div_base_x, div_base_y, hole_options, only_
gridfinityInit(3, 3, height(6), 0, 42) {
cutEqual(n_divx = 3, n_divy = 3, style_tab = 0, scoop_weight = 0);
}
gridfinityBase(3, 3, 42, 0, 0, 1);
gridfinityBase([3, 3]);
*/

// Compartments can be placed anywhere (this includes non-integer positions like 1/2 or 1/3). The grid is defined as (0,0) being the bottom left corner of the bin, with each unit being 1 base long. Each cut() module is a compartment, with the first four values defining the area that should be made into a compartment (X coord, Y coord, width, and height). These values should all be positive. t is the tab style of the compartment (0:full, 1:auto, 2:left, 3:center, 4:right, 5:none). s is a toggle for the bottom scoop.
Expand All @@ -146,7 +140,7 @@ gridfinityInit(3, 3, height(6), 0, 42) {
cut(1.5, 0, 1.5, 5/3, 2);
cut(1.5, 5/3, 1.5, 4/3, 4);
}
gridfinityBase(3, 3, 42, 0, 0, 1);
gridfinityBase([3, 3]);
*/

// Compartments can overlap! This allows for weirdly shaped compartments, such as this "2" bin.
Expand All @@ -170,7 +164,7 @@ gridfinityInit(3, 3, height(6), 0, 42) {
pattern_linear(x=1, y=3, sx=42/2)
cylinder(r=5, h=1000, center=true);
}
gridfinityBase(3, 3, 42, 0, 0, 1);
gridfinityBase([3, 3]);
*/

// You can use loops as well as the bin dimensions to make different parametric functions, such as this one, which divides the box into columns, with a small 1x1 top compartment and a long vertical compartment below
Expand All @@ -183,7 +177,7 @@ gridfinityInit(gx, gy, height(6), 0, 42) {
cut(i,gx-1,1,1);
}
}
gridfinityBase(gx, gy, 42, 0, 0, 1);
gridfinityBase([gx, gy]);
*/

// Pyramid scheme bin
Expand All @@ -195,5 +189,5 @@ gridfinityInit(gx, gy, height(6), 0, 42) {
for (j = [0:i])
cut(j*gx/(i+1),gy-i-1,gx/(i+1),1,0);
}
gridfinityBase(gx, gy, 42, 0, 0, 1);
gridfinityBase([gx, gy]);
*/
18 changes: 7 additions & 11 deletions gridfinity-rebuilt-lite.scad
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ $fs = 0.25;

/* [General Settings] */
// number of bases along x-axis
gridx = 3;
gridx = 3; //.5
// number of bases along y-axis
gridy = 3;
gridy = 3; //.5
// bin height. See bin height information and "gridz_define" below.
gridz = 6;

Expand All @@ -41,10 +41,6 @@ gridz_define = 0; // [0:gridz is the height of bins in units of 7mm increments -
style_tab = 1; //[0:Full,1:Auto,2:Left,3:Center,4:Right,5:None]

/* [Base] */
// number of divisions per 1 unit of base along the X axis. (default 1, only use integers. 0 means automatically guess the right division)
div_base_x = 0;
// number of divisions per 1 unit of base along the Y axis. (default 1, only use integers. 0 means automatically guess the right division)
div_base_y = 0;
// thickness of bottom layer
bottom_layer = 1;

Expand All @@ -70,27 +66,27 @@ hole_options = bundle_hole_options(refined_holes, magnet_holes, screw_holes, cru

// Input all the cutter types in here
color("tomato")
gridfinityLite(gridx, gridy, gridz, gridz_define, style_lip, enable_zsnap, l_grid, div_base_x, div_base_y, hole_options, only_corners) {
gridfinityLite(gridx, gridy, gridz, gridz_define, style_lip, enable_zsnap, l_grid, hole_options, only_corners) {
cutEqual(n_divx = divx, n_divy = divy, style_tab = style_tab, scoop_weight = 0);
}

// ===== CONSTRUCTION ===== //

module gridfinityLite(gridx, gridy, gridz, gridz_define, style_lip, enable_zsnap, length, div_base_x, div_base_y, style_hole, only_corners) {
module gridfinityLite(gridx, gridy, gridz, gridz_define, style_lip, enable_zsnap, length, style_hole, only_corners) {
height_mm = height(gridz, gridz_define, style_lip, enable_zsnap);
union() {
difference() {
union() {
gridfinityInit(gridx, gridy, height_mm, 0, length, sl=style_lip)
children();
gridfinityBase(gridx, gridy, length, div_base_x, div_base_y, style_hole, only_corners=only_corners);
gridfinityBase([gridx, gridy], [length, length], hole_options=style_hole, only_corners=only_corners);
}

difference() {
union() {
intersection() {
difference() {
gridfinityBase(gridx, gridy, length, div_base_x, div_base_y, style_hole, -d_wall*2, false, only_corners=only_corners);
gridfinityBase([gridx, gridy], [length, length], hole_options=style_hole, -d_wall*2, false, only_corners=only_corners);
translate([-gridx*length/2,-gridy*length/2,2*h_base])
cube([gridx*length,gridy*length,1000]);
}
Expand Down Expand Up @@ -123,7 +119,7 @@ module gridfinityLite(gridx, gridy, gridz, gridz_define, style_lip, enable_zsnap

intersection() {
difference() {
gridfinityBase(gridx, gridy, length, div_base_x, div_base_y, style_hole, -d_wall*2, false, only_corners=only_corners);
gridfinityBase([gridx, gridy], [length, length], hole_options=style_hole, -d_wall*2, false, only_corners=only_corners);
translate([-gridx*length/2,-gridy*length/2,2*h_base])
cube([gridx*length,gridy*length,1000]);
}
Expand Down
43 changes: 23 additions & 20 deletions gridfinity-rebuilt-utility.scad
Original file line number Diff line number Diff line change
Expand Up @@ -201,41 +201,44 @@ module cut_move(x, y, w, h) {

/**
*@summary Create the base of a gridfinity bin, or use it for a custom object.
* @param length X,Y size of a single Gridfinity base.
* @param grid_size Number of bases in each dimension. [x, y]
* @param grid_dimensions [length, width] of a single Gridfinity base.
* @param thumbscrew Enable "gridfinity-refined" thumbscrew hole in the center of each base unit. This is a ISO Metric Profile, 15.0mm size, M15x1.5 designation.
*/
module gridfinityBase(gx, gy, length, dx, dy, hole_options=bundle_hole_options(), off=0, final_cut=true, only_corners=false, thumbscrew=false) {
module gridfinityBase(grid_size, grid_dimensions=[l_grid, l_grid], hole_options=bundle_hole_options(), off=0, final_cut=true, only_corners=false, thumbscrew=false) {
assert(is_list(grid_dimensions) && len(grid_dimensions) == 2 &&
grid_dimensions.x > 0 && grid_dimensions.y > 0);
assert(is_list(grid_size) && len(grid_size) == 2 &&
grid_size.x > 0 && grid_size.y > 0);
assert(
is_num(gx) &&
is_num(gy) &&
is_num(length) &&
is_num(dx) &&
is_num(dy) &&
is_bool(final_cut) &&
is_bool(only_corners) &&
is_bool(thumbscrew)
);

dbnxt = [for (i=[1:5]) if (abs(gx*i)%1 < 0.001 || abs(gx*i)%1 > 0.999) i];
dbnyt = [for (i=[1:5]) if (abs(gy*i)%1 < 0.001 || abs(gy*i)%1 > 0.999) i];
dbnx = 1/(dx != 0 ? round(dx) : (len(dbnxt) > 0 ? dbnxt[0] : 1));
dbny = 1/(dy != 0 ? round(dy) : (len(dbnyt) > 0 ? dbnyt[0] : 1));

// Final size in number of bases
grid_size = [gx/dbnx, gy/dbny];

// Per spec, there's a 0.5mm gap between each base.
// This must be kept constant or half bins may not work correctly.
gap_mm = l_grid - BASE_SIZE;

base_center_distance_mm = [dbnx, dbny] * length; // Per spec this should be 42.
// Divisions per grid
// Normal, half, or quarter grid sizes supported.
// Automatically calculated using floating point comparisons.
dbnxt = [for (i=[1,2,4]) if (abs(grid_size.x*i)%1 < 0.001 || abs(grid_size.x*i)%1 > 0.999) i];
dbnyt = [for (i=[1,2,4]) if (abs(grid_size.y*i)%1 < 0.001 || abs(grid_size.y*i)%1 > 0.999) i];
assert(len(dbnxt) > 0 && len(dbnyt) > 0, "Base only supports half and quarter grid spacing.");
divisions_per_grid = [dbnxt[0], dbnyt[0]];

// Final size in number of bases
final_grid_size = [grid_size.x * divisions_per_grid.x, grid_size.y * divisions_per_grid.y];

base_center_distance_mm = [grid_dimensions.x / divisions_per_grid.x, grid_dimensions.y / divisions_per_grid.y];
individual_base_size_mm = [base_center_distance_mm.x - gap_mm, base_center_distance_mm.y - gap_mm];

// Final size of the base top. In mm.
// subtracting gap_mm here to remove an outer lip along the peremiter.
grid_size_mm = [
base_center_distance_mm.x * grid_size.x - gap_mm,
base_center_distance_mm.y * grid_size.y - gap_mm
base_center_distance_mm.x * final_grid_size.x - gap_mm,
base_center_distance_mm.y * final_grid_size.y - gap_mm
];

// Top which ties all bases together
Expand All @@ -246,7 +249,7 @@ module gridfinityBase(gx, gy, length, dx, dy, hole_options=bundle_hole_options()

if(only_corners) {
difference(){
pattern_linear(grid_size.x, grid_size.y, base_center_distance_mm.x, base_center_distance_mm.y)
pattern_linear(final_grid_size.x, final_grid_size.y, base_center_distance_mm.x, base_center_distance_mm.y)
block_base(bundle_hole_options(), 0, individual_base_size_mm, thumbscrew=thumbscrew);

copy_mirror([0, 1, 0]) {
Expand All @@ -262,7 +265,7 @@ module gridfinityBase(gx, gy, length, dx, dy, hole_options=bundle_hole_options()
}
}
else {
pattern_linear(grid_size.x, grid_size.y, base_center_distance_mm.x, base_center_distance_mm.y)
pattern_linear(final_grid_size.x, final_grid_size.y, base_center_distance_mm.x, base_center_distance_mm.y)
block_base(hole_options, off, individual_base_size_mm, thumbscrew=thumbscrew);
}
}
Expand Down

0 comments on commit d4b5b1c

Please sign in to comment.