From 60b84331e9701081d5141af290d5867d278d6c73 Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Thu, 28 Jul 2022 18:40:21 -0700 Subject: [PATCH 1/2] Fix for issue #666 --- drawing.scad | 40 ++++++++++++++++++++++++++++------------ nema_steppers.scad | 3 ++- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/drawing.scad b/drawing.scad index bb7a08e..2854856 100644 --- a/drawing.scad +++ b/drawing.scad @@ -552,41 +552,57 @@ module stroke( // --- // width = The width of the dashed line to draw. Module only. Default: 1 // closed = If true, treat path as a closed polygon. Default: false +// fit = If true, shrink or stretch the dash pattern so that the path ends ofter a logical dash. Default: true +// roundcaps = (Module only) If true, draws dashes with rounded caps. This often looks better. Default: true +// mindash = (Function only) Specifies the minimal dash length to return at the end of a path when fit is false. Default: 0.5 // Example(2D): Open Path // path = [for (a=[-180:10:180]) [a/3,20*sin(a)]]; // dashed_stroke(path, [3,2], width=1); // Example(2D): Closed Polygon // path = circle(d=100,$fn=72); -// dashpat = [10,2,3,2,3,2]; +// dashpat = [10,2, 3,2, 3,2]; // dashed_stroke(path, dashpat, width=1, closed=true); // Example(FlatSpin,VPD=250): 3D Dashed Path // path = [for (a=[-180:5:180]) [a/3, 20*cos(3*a), 20*sin(3*a)]]; // dashed_stroke(path, [3,2], width=1); -function dashed_stroke(path, dashpat=[3,3], closed=false) = - is_region(path) ? [for(p=path) each dashed_stroke(p,dashpat,closed=true)] : +function dashed_stroke(path, dashpat=[3,3], closed=false, fit=true, mindash=0.5) = + is_region(path) ? [ + for (p = path) + each dashed_stroke(p, dashpat, closed=true, fit=fit) + ] : let( path = closed? close_path(path) : path, dashpat = len(dashpat)%2==0? dashpat : concat(dashpat,[0]), plen = path_length(path), dlen = sum(dashpat), doff = cumsum(dashpat), - reps = floor(plen / dlen), - step = plen / reps, + freps = plen / dlen, + reps = max(1, fit? round(freps) : floor(freps)), + tlen = !fit? plen : + reps * dlen + (closed? 0 : dashpat[0]), + sc = plen / tlen, cuts = [ - for (i=[0:1:reps-1], off=doff) - let (st=i*step, x=st+off) - if (x>0 && x 0 && x < plen) x ], dashes = path_cut(path, cuts, closed=false), - evens = [for (i=idx(dashes)) if (i%2==0) dashes[i]] + dcnt = len(dashes), + evens = [ + for (i = idx(dashes)) + if (i % 2 == 0) + let( dash = dashes[i] ) + if (i < dcnt-1 || path_length(dash) > mindash) + dashes[i] + ] ) evens; -module dashed_stroke(path, dashpat=[3,3], width=1, closed=false) { +module dashed_stroke(path, dashpat=[3,3], width=1, closed=false, fit=true, roundcaps=false) { no_children($children); - segs = dashed_stroke(path, dashpat=dashpat*width, closed=closed); + segs = dashed_stroke(path, dashpat=dashpat*width, closed=closed, fit=fit, mindash=0.5*width); for (seg = segs) - stroke(seg, width=width, endcaps=false); + stroke(seg, width=width, endcaps=roundcaps? "round" : false); } diff --git a/nema_steppers.scad b/nema_steppers.scad index 2141579..557297d 100644 --- a/nema_steppers.scad +++ b/nema_steppers.scad @@ -16,7 +16,8 @@ // Usage: // nema_stepper_motor(size, h, shaft_len, ...) [attachments]; // Topics: Parts, Motors -// Description: Creates a model of a NEMA 11 stepper motor. +// Description: +// Creates a model of a NEMA standard stepper motor. // Arguments: // size = The NEMA standard size of the stepper motor. // h = Length of motor body. Default: 24mm From 4aee209114984205b23e8a944e4f8720be46c25a Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Thu, 28 Jul 2022 23:49:24 -0700 Subject: [PATCH 2/2] Torx sizing tweaks. --- screw_drive.scad | 176 ++++++++++++------------------------ tests/test_drawing.scad | 4 +- tests/test_screw_drive.scad | 45 ++------- 3 files changed, 64 insertions(+), 161 deletions(-) diff --git a/screw_drive.scad b/screw_drive.scad index a1b63cb..f94bf3f 100644 --- a/screw_drive.scad +++ b/screw_drive.scad @@ -143,8 +143,8 @@ function phillips_diam(size, depth) = // Examples: // torx_mask(size=30, l=10, $fa=1, $fs=1); module torx_mask(size, l=5, center, anchor, spin=0, orient=UP) { - anchor = get_anchor(anchor, center, BOT, BOT); od = torx_diam(size); + anchor = get_anchor(anchor, center, BOT, BOT); attachable(anchor,spin,orient, d=od, l=l) { linear_extrude(height=l, convexity=4, center=true) { torx_mask2d(size); @@ -165,10 +165,11 @@ module torx_mask(size, l=5, center, anchor, spin=0, orient=UP) { // torx_mask2d(size=30, $fa=1, $fs=1); module torx_mask2d(size) { no_children($children); - od = torx_diam(size); - id = _torx_inner_diam(size); - tip = _torx_tip_radius(size); - rounding = _torx_rounding_radius(size); + info = torx_info(size); + od = info[0]; + id = info[1]; + tip = info[3]; + rounding = info[4]; base = od - 2*tip; $fn = quantup(segs(od/2),12); difference() { @@ -195,57 +196,62 @@ module torx_mask2d(size) { } +// Function: torx_info() +// Usage: +// info = torx_info(size); +// Description: +// Get the typical dimensional info for a given Torx size. +// Returns a list containing, in order: +// - Outer Diameter +// - Inner Diameter +// - Drive Hole Depth +// - External Tip Rounding Radius +// - Inner Rounding Radius +// Arguments: +// size = Torx size. +function torx_info(size) = + let( + info_arr = [ + //T# OD ID H Re Ri + [ 1, [ 0.90, 0.65, 1.19, 0.059, 0.201]], + [ 2, [ 1.00, 0.73, 1.70, 0.069, 0.224]], + [ 3, [ 1.20, 0.87, 1.70, 0.081, 0.266]], + [ 4, [ 1.35, 0.98, 1.70, 0.090, 0.308]], + [ 5, [ 1.48, 1.08, 1.70, 0.109, 0.330]], + [ 6, [ 1.75, 1.27, 1.87, 0.132, 0.383]], + [ 7, [ 2.08, 1.50, 3.10, 0.161, 0.446]], + [ 8, [ 2.40, 1.75, 3.10, 0.190, 0.510]], + [ 9, [ 2.58, 1.87, 3.35, 0.207, 0.554]], + [ 10, [ 2.80, 2.05, 3.61, 0.229, 0.598]], + [ 15, [ 3.35, 2.40, 3.86, 0.267, 0.716]], + [ 20, [ 3.95, 2.85, 4.12, 0.305, 0.859]], + [ 25, [ 4.50, 3.25, 4.50, 0.375, 0.920]], + [ 27, [ 5.07, 3.65, 4.75, 0.390, 1.108]], + [ 30, [ 5.60, 4.05, 5.00, 0.451, 1.194]], + [ 40, [ 6.75, 4.85, 5.64, 0.546, 1.428]], + [ 45, [ 7.93, 5.64, 6.27, 0.574, 1.796]], + [ 50, [ 8.95, 6.45, 6.53, 0.775, 1.816]], + [ 55, [ 11.35, 8.05, 6.78, 0.867, 2.667]], + [ 60, [ 13.45, 9.60, 8.22, 1.067, 2.883]], + [ 70, [ 15.70, 11.20, 9.01, 1.194, 3.477]], + [ 80, [ 17.75, 12.80, 9.95, 1.526, 3.627]], + [ 90, [ 20.20, 14.40, 10.61, 1.530, 4.468]], + [100, [ 22.40, 16.00, 11.40, 1.720, 4.925]], + ], + found = [for(info=info_arr) if(info[0]==size) info[1]] + ) + assert(found, "Unsupported Torx size.") + found[0]; + + // Function: torx_diam() // Usage: // diam = torx_diam(size); // Description: Get the typical outer diameter of Torx profile. // Arguments: // size = Torx size. -function torx_diam(size) = lookup(size, [ - [ 6, 1.75], - [ 8, 2.40], - [ 10, 2.80], - [ 15, 3.35], - [ 20, 3.95], - [ 25, 4.50], - [ 30, 5.60], - [ 40, 6.75], - [ 45, 7.93], - [ 50, 8.95], - [ 55, 11.35], - [ 60, 13.45], - [ 70, 15.70], - [ 80, 17.75], - [ 90, 20.20], - [100, 22.40] -]); - +function torx_diam(size) = torx_info(size)[0]; -/// Internal Function: torx_inner_diam() -/// Usage: -/// diam = torx_inner_diam(size); -/// Description: Get typical inner diameter of Torx profile. -/// Arguments: -/// size = Torx size. -function _torx_inner_diam(size) = lookup(size, [ - [ 6, 1.27], - [ 8, 1.75], - [ 10, 2.05], - [ 15, 2.40], - [ 20, 2.85], - [ 25, 3.25], - [ 30, 4.05], - [ 40, 4.85], - [ 45, 5.64], - [ 50, 6.45], - [ 55, 8.05], - [ 60, 9.60], - [ 70, 11.20], - [ 80, 12.80], - [ 90, 14.40], - [100, 16.00] -]); - // Function: torx_depth() // Usage: @@ -253,77 +259,7 @@ function _torx_inner_diam(size) = lookup(size, [ // Description: Gets typical drive hole depth. // Arguments: // size = Torx size. -function torx_depth(size) = lookup(size, [ - [ 6, 1.82], - [ 8, 3.05], - [ 10, 3.56], - [ 15, 3.81], - [ 20, 4.07], - [ 25, 4.45], - [ 30, 4.95], - [ 40, 5.59], - [ 45, 6.22], - [ 50, 6.48], - [ 55, 6.73], - [ 60, 8.17], - [ 70, 8.96], - [ 80, 9.90], - [ 90, 10.56], - [100, 11.35] -]); - - -/// Internal Function: torx_tip_radius() -/// Usage: -/// rad = torx_tip_radius(size); -/// Description: Gets minor rounding radius of Torx profile. -/// Arguments: -/// size = Torx size. -function _torx_tip_radius(size) = lookup(size, [ - [ 6, 0.132], - [ 8, 0.190], - [ 10, 0.229], - [ 15, 0.267], - [ 20, 0.305], - [ 25, 0.375], - [ 30, 0.451], - [ 40, 0.546], - [ 45, 0.574], - [ 50, 0.775], - [ 55, 0.867], - [ 60, 1.067], - [ 70, 1.194], - [ 80, 1.526], - [ 90, 1.530], - [100, 1.720] -]); - - -/// Internal Function: torx_rounding_radius() -/// Usage: -/// rad = torx_rounding_radius(size); -/// Description: Gets major rounding radius of Torx profile. -/// Arguments: -/// size = Torx size. -function _torx_rounding_radius(size) = lookup(size, [ - [ 6, 0.383], - [ 8, 0.510], - [ 10, 0.598], - [ 15, 0.716], - [ 20, 0.859], - [ 25, 0.920], - [ 30, 1.194], - [ 40, 1.428], - [ 45, 1.796], - [ 50, 1.816], - [ 55, 2.667], - [ 60, 2.883], - [ 70, 3.477], - [ 80, 3.627], - [ 90, 4.468], - [100, 4.925] -]); - +function torx_depth(size) = torx_info(size)[2]; diff --git a/tests/test_drawing.scad b/tests/test_drawing.scad index 74e54d0..8162690 100644 --- a/tests/test_drawing.scad +++ b/tests/test_drawing.scad @@ -53,8 +53,8 @@ test_arc(); module test_dashed_stroke() { - segs = dashed_stroke([[0,0],[10,0]], dashpat=[3,2], closed=false); - assert_equal(segs,[[[0,0],[3,0]], [[5,0],[8,0]]]); + segs = dashed_stroke([[0,0],[15,0]], dashpat=[3,2], closed=false); + assert_approx(segs,[[[0,0],[2.5,0]],[[4+1/6,0],[6+2/3,0]],[[8+1/3,0],[10+5/6,0]],[[12.5,0],[15,0]]]); } test_dashed_stroke(); diff --git a/tests/test_screw_drive.scad b/tests/test_screw_drive.scad index e71cda0..08c7e85 100644 --- a/tests/test_screw_drive.scad +++ b/tests/test_screw_drive.scad @@ -13,49 +13,16 @@ module test_torx_diam() { test_torx_diam(); -module test_torx_inner_diam() { - assert_approx(_torx_inner_diam(10), 2.05); - assert_approx(_torx_inner_diam(15), 2.40); - assert_approx(_torx_inner_diam(20), 2.85); - assert_approx(_torx_inner_diam(25), 3.25); - assert_approx(_torx_inner_diam(30), 4.05); - assert_approx(_torx_inner_diam(40), 4.85); -} -test_torx_inner_diam(); - - module test_torx_depth() { - assert_approx(torx_depth(10), 3.56); - assert_approx(torx_depth(15), 3.81); - assert_approx(torx_depth(20), 4.07); - assert_approx(torx_depth(25), 4.45); - assert_approx(torx_depth(30), 4.95); - assert_approx(torx_depth(40), 5.59); + assert_approx(torx_depth(10), 3.61); + assert_approx(torx_depth(15), 3.86); + assert_approx(torx_depth(20), 4.12); + assert_approx(torx_depth(25), 4.50); + assert_approx(torx_depth(30), 5,00); + assert_approx(torx_depth(40), 5.64); } test_torx_depth(); -module test_torx_tip_radius() { - assert_approx(_torx_tip_radius(10), 0.229); - assert_approx(_torx_tip_radius(15), 0.267); - assert_approx(_torx_tip_radius(20), 0.305); - assert_approx(_torx_tip_radius(25), 0.375); - assert_approx(_torx_tip_radius(30), 0.451); - assert_approx(_torx_tip_radius(40), 0.546); -} -test_torx_tip_radius(); - - -module test_torx_rounding_radius() { - assert_approx(_torx_rounding_radius(10), 0.598); - assert_approx(_torx_rounding_radius(15), 0.716); - assert_approx(_torx_rounding_radius(20), 0.859); - assert_approx(_torx_rounding_radius(25), 0.920); - assert_approx(_torx_rounding_radius(30), 1.194); - assert_approx(_torx_rounding_radius(40), 1.428); -} -test_torx_rounding_radius(); - - // vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap