Skip to content

Commit

Permalink
improve keyhole and round_path
Browse files Browse the repository at this point in the history
  • Loading branch information
lijon committed Feb 7, 2024
1 parent 8badc48 commit 4cfbe71
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion box.scad
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module box_part(half_sides, anchor=CENTER, spin, inside=true, auto_anchor=true,
}
}

function round_path(path, r) = offset(offset(path,r),-r);
function round_path(path, r, closed=true) = r==0 ? path : offset(offset(path,r,closed=closed),-r,closed=closed);

function vector_name(v) =
assert(is_vector(v))
Expand Down
11 changes: 10 additions & 1 deletion examples/boxsides.scad
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
include <jl_scad/box.scad>
include <jl_scad/parts.scad>

// $fa = 1;
// $fn = 48;

$fs=$preview?0.5:0.125;
$fa = 1;
$fn = 48;

module my_box(size) {
// a test box with one piece per side
Expand Down Expand Up @@ -46,3 +49,9 @@ my_box(sz)
// position(LEFT+FRONT)
// cube([15,15,sz.z*0.75],anchor=CENTER,spin=45);
}

// p = keyhole(r=0);
// !union() {
// region(p);
// move_copies(p) color("red",0.5) circle(d=0.2,$fn=8);
// }
4 changes: 2 additions & 2 deletions examples/example.scad
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ box_shell_base_lid([50,40,20],wall_sides=2,wall_top=1,rim_gap=0,rbot=1,rbot_insi
// inspect by cutting away corner, we don't use box_part() or box_pos(), but manually position the cube.
box_half(BOX_ALL) position(CENTER) box_cut("#58c") cube(30,anchor=LEFT+BACK);

Y(-2) box_part(BOT,BACK) box_cutout(keyhole(),anchor=BACK);
}
Y(-3) box_part(BOT,BACK) box_cutout(keyhole(),anchor=BACK);
}
8 changes: 4 additions & 4 deletions parts.scad
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ function keyhole_old(d1=3,d2=7,l=5,joint=1) = zrot(180, path_join([
[[0,l],[0,0]],
],joint=joint));

function keyhole(d1=3,d2=6,l,r) =
let(r=default(r,d1/2),l=d2)
function keyhole(d1=3,d2=6,l,r,n=24) =
let(r=default(r,d1/2),l=d2,$fn=n) // fn must be even for this to work!
assert(r<d1)
round_path(union([
force_path(round_path(union([
circle(d=d1),
rect([d1,l],anchor=TOP),
move([0,-l],circle(d=d2)),
]),r);
]),r));

// p: path of cutout
// rounding: roundover outer edge
Expand Down

0 comments on commit 4cfbe71

Please sign in to comment.