From 1fb449fdf6025ed4826b79107295e79ececc946c Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 27 May 2022 09:10:35 +0800 Subject: [PATCH] refactor and add smooth params --- examples/differential_line_growth.scad | 25 ++++++++++++------- .../_impl/_differential_line_growth.scad | 22 +++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/differential_line_growth.scad b/examples/differential_line_growth.scad index a84eb683..938eb006 100644 --- a/examples/differential_line_growth.scad +++ b/examples/differential_line_growth.scad @@ -1,18 +1,25 @@ use ; use ; - +use ; + $fn = 24; -r = 20; -times = 50; +r = 10; +times = 80; thickness = 2; +smooth = true; +smooth_times = 2; node_option = [ - 0.5, // maxForce - 0.7, // maxSpeed - 12, // separationDistance - 1.5, // separationCohesionRatio - 10 // maxEdgeLength + 0.4, // maxForce + 0.5, // maxSpeed + 5, // separationDistance + 1.2, // separationCohesionRatio + 4 // maxEdgeLength ]; init_shape = shape_circle(r); +poly = differential_line_growth(init_shape, node_option, times); + linear_extrude(thickness) - polygon(differential_line_growth(init_shape, node_option, times)); + polygon( + smooth ? midpt_smooth(poly, smooth_times, true) : poly + ); diff --git a/src/experimental/_impl/_differential_line_growth.scad b/src/experimental/_impl/_differential_line_growth.scad index 7b673760..d5a61446 100644 --- a/src/experimental/_impl/_differential_line_growth.scad +++ b/src/experimental/_impl/_differential_line_growth.scad @@ -89,18 +89,22 @@ function updateAllSeperation(allSeperation, allSeperationFrom_i_1, leng, n) = [ function differentiate(nodes, leng) = [ for(i = 0, - allSep = [for(i = [0:leng - 1]) ZERO_VT], - allSeperationFrom_i_1 = allSeperationFrom(nodes, leng, nodes[i], i + 1); - i < leng; - allSep = updateAllSeperation(allSep, allSeperationFrom_i_1, leng, i + 1), + j = 1, + allSeperationFrom_i_1 = allSeperationFrom(nodes, leng, nodes[i], j), + allSep = [ZERO_VT, each -allSeperationFrom_i_1], + running = i < leng; + running; i = i + 1, - allSeperationFrom_i_1 = i < leng ? allSeperationFrom(nodes, leng, nodes[i], i + 1) : undef + j = j + 1, + running = i < leng, + allSeperationFrom_i_1 = running ? allSeperationFrom(nodes, leng, nodes[i], j) : undef, + allSep = running ? updateAllSeperation(allSep, allSeperationFrom_i_1, leng, j) : undef ) - let( - seperation_i = sum([allSep[i], each allSeperationFrom_i_1]), - cohesion_i = cohesion(nodes, leng, i) + applyForceTo( + nodes[i], + sum([allSep[i], each allSeperationFrom_i_1]), + cohesion(nodes, leng, i) ) - applyForceTo(nodes[i], seperation_i, cohesion_i) ]; function _differential_line_growth(nodes) =