From b044ad9619d03839b03ecbdfdf853050213f346f Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 13 May 2025 18:35:25 -0400 Subject: [PATCH] add fill() and hinge doc tweaks --- hinges.scad | 18 +++++++++++++++++- regions.scad | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/hinges.scad b/hinges.scad index 3ae10ecb..70367e45 100644 --- a/hinges.scad +++ b/hinges.scad @@ -98,8 +98,8 @@ include // right(.5)fwd(-3)color("blue")text("round_bot=1.5",size=1); // Arguments: // length = total length of the entire hinge -// offset = horizontal offset of the hinge pin center from the mount point // segs = number of hinge segments +// offset = horizontal offset of the hinge pin center from the mount point // inner = set to true for the "inner" hinge. Default: false // --- // arm_height = vertical height of the arm that holds the hinge barrel. Default: 0 @@ -216,6 +216,22 @@ include // cuboid([4,40,15]) // position(TOP+RIGHT) orient(anchor=RIGHT) // knuckle_hinge(length=35, segs=5, offset=2, inner=true, knuckle_clearance=1); +// Example(3D,NoScales,VPR=[57.80,0.00,308.00],VPD=54.24,VPT=[2.34,0.76,0.15]): If you want the hinge leaves to fold flat together, pick a hinge configuration that places the centerline of the hinge pin on the plane of the hinge leaf. Hinges that fold entirely flat probably won't work, so we add some clearance between the leaves. +// $fn=32; +// thickness=2; +// clearance=.2; +// yflip_copy() +// color(["green","red"][$idx]) +// diff() +// fwd(clearance/2) +// cuboid([20,thickness,7],anchor=BACK) +// back(clearance/2) +// down(thickness/3) +// position(TOP+BACK) +// knuckle_hinge(20, segs=5, offset=thickness+clearance, +// inner=$orig, knuckle_clearance=clearance, +// knuckle_diam=2*thickness+clearance, +// arm_angle=90, arm_height=0, clear_top=true); function knuckle_hinge(length, segs, offset, inner=false, arm_height=0, arm_angle=45, gap=0.2, seg_ratio=1, knuckle_diam=4, pin_diam=1.75, fill=true, clear_top=false, diff --git a/regions.scad b/regions.scad index 28c2cf3a..1a5aeefb 100644 --- a/regions.scad +++ b/regions.scad @@ -1523,4 +1523,48 @@ module hull_region(region) } +// Function: fill() +// Synopsis: Remove holes from a {{region}} +// SynTags: Geom, Path +// Topics: Regions, Polygons, Shapes2D +// Usage: +// filled = fill(region); +// Description: +// Given a {{region}}, fill in any internal holes in the components of the region. This returns the outside border of each region component, and +// is equivalent to {{hull()}} for region components whose outside boundary is convex. +// Arguments: +// region = region to fill +// Example(2D, NoAxes): The original region in green has internal holes and subparts that are all filled in on the yellow filled region. +// $fs=.5;$fa=1; +// reg=[circle(r=10),right(5.5,circle(r=1)), +// circle(r=8), circle(r=3), +// right(5.5,rect([3,4]))]; +// color("green")region(reg); +// right(25)region(fill(reg)); +// Example(2D, NoAxes): Here the input region in green has two components: +// reg = [circle(8), circle(6)]; +// reg2 = union([reg, fwd(18,reg)]); +// color("green")region(reg2); +// right(18) region(fill(reg2)); + +function fill(region) = + let( + region = force_region(region) + ) + assert(is_region(region), "\nInput is not a region.") + let( + inside = [for(i=idx(region)) + let(pt = mean([region[i][0], region[i][1]])) + [for(j=idx(region)) i==j ? 0 + : point_in_polygon(pt,region[j]) >=0 ? 1 : 0] + ], + level = inside*repeat(1,len(region)) + ) + [ for(i=idx(region)) + if(level[i]==0) clockwise_polygon(region[i])]; + + + + + // vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap