Merge pull request #822 from revarbat/revarbat_dev

Tweaks for teardrop() Example.
This commit is contained in:
Revar Desmera 2022-03-31 15:00:38 -07:00 committed by GitHub
commit 93fcc98b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 80 deletions

View File

@ -159,9 +159,10 @@ function line_of(spacing, n, l, p1, p2) =
// Usage:
// xcopies(spacing, [n], [sp]) children;
// xcopies(l, [n], [sp]) children;
// xcopies(LIST) children;
//
// 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].
@ -180,15 +181,26 @@ 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)
{
req_children($children);
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();
}
}
@ -200,9 +212,10 @@ module xcopies(spacing, n, l, sp)
// Usage:
// ycopies(spacing, [n], [sp]) children;
// ycopies(l, [n], [sp]) children;
// ycopies(LIST) children;
//
// 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].
@ -221,15 +234,26 @@ 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)
{
req_children($children);
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();
}
}
@ -239,11 +263,13 @@ module ycopies(spacing, n, l, sp)
// Spreads out `n` copies of the children along a line on the Z axis.
//
// Usage:
// zcopies(spacing, [n], [sp]) children;
// zcopies(l, [n], [sp]) children;
// zcopies(LIST) children;
//
// 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].
@ -276,15 +302,26 @@ 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)
{
req_children($children);
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();
}
}
@ -422,64 +459,6 @@ module grid2d(spacing, n, size, stagger=false, inside=undef, nonzero)
}
// Module: grid3d()
//
// Description:
// Makes a 3D grid of duplicate children.
//
// Usage:
// grid3d(spacing,n) children;
// grid3d(spacing=[dX,dY,dZ], n=[Xn,Yn,Zn]) children;
// grid3d([xa=], [ya=], [za=]) children;
//
// 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=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:
// 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])
{
req_children($children);
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
//////////////////////////////////////////////////////////////////////

View File

@ -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)