From 18f013ebb8629035a31381157e561b1cba408638 Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Wed, 30 Mar 2022 19:26:47 -0700 Subject: [PATCH 1/3] Tweaks for teardrop() Example. --- shapes3d.scad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapes3d.scad b/shapes3d.scad index dd5f2fdb..7e9b319e 100644 --- a/shapes3d.scad +++ b/shapes3d.scad @@ -2261,7 +2261,7 @@ function torus( // Example: Standard Conical Connectors // teardrop(d1=20, d2=30, h=20, cap_h1=11, cap_h2=16) // show_anchors(custom=false); -// Example(Spin,VPD=275): Named Conical Connectors +// Example(Spin,VPD=150,Med): Named Conical Connectors // teardrop(d1=20, d2=30, h=20, cap_h1=11, cap_h2=16) // show_anchors(std=false); module teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, l, anchor=CENTER, spin=0, orient=UP) From 3af1e96f6f6e67e21884a854cfb784a9c5787fce Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Wed, 30 Mar 2022 21:25:49 -0700 Subject: [PATCH 2/3] Minor distributors example image tweaks. --- distributors.scad | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/distributors.scad b/distributors.scad index a5af6c48..02128111 100644 --- a/distributors.scad +++ b/distributors.scad @@ -429,28 +429,31 @@ module grid2d(spacing, n, size, stagger=false, inside=undef, nonzero) // grid3d([xa], [ya], [za]) ... // // Arguments: +// spacing = spacing of copies per axis. Use with `n`. +// n = Optional number of copies to have per axis. // xa = array or range of X-axis values to offset by. (Default: [0]) // ya = array or range of Y-axis values to offset by. (Default: [0]) // za = array or range of Z-axis values to offset by. (Default: [0]) -// n = Optional number of copies to have per axis. -// spacing = spacing of copies per axis. Use with `n`. // // Side Effects: // `$pos` is set to the relative centerpoint of each child copy, and can be used to modify each child individually. // `$idx` is set to the [Xidx,Yidx,Zidx] index values of each child copy, when using `count` and `n`. // -// Examples(FlatSpin,VPD=222): -// grid3d(xa=[0:25:50],ya=[0,40],za=[-20:40:20]) sphere(r=5); -// Examples(FlatSpin,VPD=800): -// grid3d(n=[3, 4, 2], spacing=[60, 50, 40]) sphere(r=10); +// Examples(FlatSpin,VPD=240,VPT=[25,20,0]): +// grid3d(xa=[0:25:50],ya=[0,40],za=[-20:40:20]) +// sphere(r=5); +// Examples(FlatSpin,VPD=700): +// grid3d(n=[3, 4, 2], spacing=[60, 50, 40]) +// sphere(r=10); // Examples: // grid3d(ya=[-60:40:60],za=[0,70]) sphere(r=10); // grid3d(n=3, spacing=30) sphere(r=10); // grid3d(n=[3, 1, 2], spacing=30) sphere(r=10); // grid3d(n=[3, 4], spacing=[80, 60]) sphere(r=10); // Examples: -// grid3d(n=[10, 10, 10], spacing=50) color($idx/9) cube(50, center=true); -module grid3d(xa=[0], ya=[0], za=[0], n=undef, spacing=undef) +// grid3d(n=[10, 10, 10], spacing=50) +// color($idx/9) cube(50, center=true); +module grid3d(spacing, n, xa=[0], ya=[0], za=[0]) { n = scalar_vec3(n, 1); spacing = scalar_vec3(spacing, undef); From 7e73af8dab80d28304f59add373c8110d83f5bee Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Thu, 31 Mar 2022 14:16:12 -0700 Subject: [PATCH 3/3] Removed grid3d(), enabled [xyz]copies(LIST)... --- distributors.scad | 137 +++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 80 deletions(-) diff --git a/distributors.scad b/distributors.scad index 02128111..64c6de9a 100644 --- a/distributors.scad +++ b/distributors.scad @@ -157,9 +157,10 @@ function line_of(spacing, n, l, p1, p2) = // Usage: // xcopies(spacing, [n], [sp]) ... // xcopies(l, [n], [sp]) ... +// xcopies(LIST) ... // // Arguments: -// spacing = spacing between copies. (Default: 1.0) +// spacing = Given a scalar, specifies a uniform spacing between copies. Given a list of scalars, each one gives a specific position along the line. (Default: 1.0) // n = Number of copies to spread out. (Default: 2) // l = Length to spread copies over. // sp = If given as a point, copies will be spread on a line to the right of starting position `sp`. If given as a scalar, copies will be spread on a line to the right of starting position `[sp,0,0]`. If not given, copies will be spread along a line that is centered at [0,0,0]. @@ -178,14 +179,25 @@ function line_of(spacing, n, l, p1, p2) = // cube(size=[1,3,1],center=true); // cube(size=[3,1,1],center=true); // } +// Example: +// xcopies([1,2,3,5,7]) sphere(d=1); module xcopies(spacing, n, l, sp) { - sp = is_finite(sp)? [sp,0,0] : sp; - line_of( - l=u_mul(l,RIGHT), - spacing=u_mul(spacing,RIGHT), - n=n, p1=sp - ) children(); + dir = RIGHT; + sp = is_finite(sp)? (sp*dir) : sp; + if (is_vector(spacing)) { + translate(default(sp,[0,0,0])) { + for (x = spacing) { + translate(x*dir) children(); + } + } + } else { + line_of( + l=u_mul(l,dir), + spacing=u_mul(spacing,dir), + n=n, p1=sp + ) children(); + } } @@ -197,9 +209,10 @@ module xcopies(spacing, n, l, sp) // Usage: // ycopies(spacing, [n], [sp]) ... // ycopies(l, [n], [sp]) ... +// ycopies(LIST) ... // // Arguments: -// spacing = spacing between copies. (Default: 1.0) +// spacing = Given a scalar, specifies a uniform spacing between copies. Given a list of scalars, each one gives a specific position along the line. (Default: 1.0) // n = Number of copies to spread out. (Default: 2) // l = Length to spread copies over. // sp = If given as a point, copies will be spread on a line back from starting position `sp`. If given as a scalar, copies will be spread on a line back from starting position `[0,sp,0]`. If not given, copies will be spread along a line that is centered at [0,0,0]. @@ -218,14 +231,25 @@ module xcopies(spacing, n, l, sp) // cube(size=[1,3,1],center=true); // cube(size=[3,1,1],center=true); // } +// Example: +// ycopies([1,2,3,5,7]) sphere(d=1); module ycopies(spacing, n, l, sp) { - sp = is_finite(sp)? [0,sp,0] : sp; - line_of( - l=u_mul(l,BACK), - spacing=u_mul(spacing,BACK), - n=n, p1=sp - ) children(); + dir = BACK; + sp = is_finite(sp)? (sp*dir) : sp; + if (is_vector(spacing)) { + translate(default(sp,[0,0,0])) { + for (x = spacing) { + translate(x*dir) children(); + } + } + } else { + line_of( + l=u_mul(l,dir), + spacing=u_mul(spacing,dir), + n=n, p1=sp + ) children(); + } } @@ -237,9 +261,10 @@ module ycopies(spacing, n, l, sp) // Usage: // zcopies(spacing, [n], [sp]) ... // zcopies(l, [n], [sp]) ... +// zcopies(LIST) ... // // Arguments: -// spacing = spacing between copies. (Default: 1.0) +// spacing = Given a scalar, specifies a uniform spacing between copies. Given a list of scalars, each one gives a specific position along the line. (Default: 1.0) // n = Number of copies to spread out. (Default: 2) // l = Length to spread copies over. // sp = If given as a point, copies will be spread on a line up from starting position `sp`. If given as a scalar, copies will be spread on a line up from starting position `[0,0,sp]`. If not given, copies will be spread along a line that is centered at [0,0,0]. @@ -272,14 +297,25 @@ module ycopies(spacing, n, l, sp) // back(($idx%2)*xyr*cos(60)) // grid2d(s,n=[12,7],stagger=($idx%2)? "alt" : true) // sphere(d=s); +// Example: +// zcopies([1,2,3,5,7]) sphere(d=1); module zcopies(spacing, n, l, sp) { - sp = is_finite(sp)? [0,0,sp] : sp; - line_of( - l=u_mul(l,UP), - spacing=u_mul(spacing,UP), - n=n, p1=sp - ) children(); + dir = UP; + sp = is_finite(sp)? (sp*dir) : sp; + if (is_vector(spacing)) { + translate(default(sp,[0,0,0])) { + for (x = spacing) { + translate(x*dir) children(); + } + } + } else { + line_of( + l=u_mul(l,dir), + spacing=u_mul(spacing,dir), + n=n, p1=sp + ) children(); + } } @@ -418,65 +454,6 @@ module grid2d(spacing, n, size, stagger=false, inside=undef, nonzero) -// Module: grid3d() -// -// Description: -// Makes a 3D grid of duplicate children. -// -// Usage: -// grid3d(n, spacing) ... -// grid3d(n=[Xn,Yn,Zn], spacing=[dX,dY,dZ]) ... -// grid3d([xa], [ya], [za]) ... -// -// Arguments: -// spacing = spacing of copies per axis. Use with `n`. -// n = Optional number of copies to have per axis. -// xa = array or range of X-axis values to offset by. (Default: [0]) -// ya = array or range of Y-axis values to offset by. (Default: [0]) -// za = array or range of Z-axis values to offset by. (Default: [0]) -// -// Side Effects: -// `$pos` is set to the relative centerpoint of each child copy, and can be used to modify each child individually. -// `$idx` is set to the [Xidx,Yidx,Zidx] index values of each child copy, when using `count` and `n`. -// -// Examples(FlatSpin,VPD=240,VPT=[25,20,0]): -// grid3d(xa=[0:25:50],ya=[0,40],za=[-20:40:20]) -// sphere(r=5); -// Examples(FlatSpin,VPD=700): -// grid3d(n=[3, 4, 2], spacing=[60, 50, 40]) -// sphere(r=10); -// Examples: -// grid3d(ya=[-60:40:60],za=[0,70]) sphere(r=10); -// grid3d(n=3, spacing=30) sphere(r=10); -// grid3d(n=[3, 1, 2], spacing=30) sphere(r=10); -// grid3d(n=[3, 4], spacing=[80, 60]) sphere(r=10); -// Examples: -// grid3d(n=[10, 10, 10], spacing=50) -// color($idx/9) cube(50, center=true); -module grid3d(spacing, n, xa=[0], ya=[0], za=[0]) -{ - n = scalar_vec3(n, 1); - spacing = scalar_vec3(spacing, undef); - if (!is_undef(n) && !is_undef(spacing)) { - for (xi = [0:1:n.x-1]) { - for (yi = [0:1:n.y-1]) { - for (zi = [0:1:n.z-1]) { - $idx = [xi,yi,zi]; - $pos = v_mul(spacing, $idx - (n-[1,1,1])/2); - translate($pos) children(); - } - } - } - } else { - for (xoff = xa, yoff = ya, zoff = za) { - $pos = [xoff, yoff, zoff]; - translate($pos) children(); - } - } -} - - - ////////////////////////////////////////////////////////////////////// // Section: Rotating copies of all children //////////////////////////////////////////////////////////////////////