Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianVmariano committed Oct 17, 2023
2 parents fb483af + dcc76c2 commit 7d2b547
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 77 deletions.
123 changes: 108 additions & 15 deletions attachments.scad
Original file line number Diff line number Diff line change
Expand Up @@ -3248,7 +3248,11 @@ function _find_anchor(anchor, geom) =
let(
size=geom[1], size2=geom[2],
shift=point2d(geom[3]), axis=point3d(geom[4]),
override = geom[5](anchor),
override = geom[5](anchor)
)
let(
size = [for (c = size) max(0,c)],
size2 = [for (c = size2) max(0,c)],
anch = rot(from=axis, to=UP, p=anchor),
offset = rot(from=axis, to=UP, p=offset),
h = size.z,
Expand All @@ -3259,8 +3263,8 @@ function _find_anchor(anchor, geom) =
pos = point3d(cp) + lerp(bot,top,u) + offset,
vecs = anchor==CENTER? [UP]
: [
if (anch.x!=0) unit(rot(from=UP, to=[(top-bot).x,0,h], p=[axy.x,0,0]), UP),
if (anch.y!=0) unit(rot(from=UP, to=[0,(top-bot).y,h], p=[0,axy.y,0]), UP),
if (anch.x!=0) unit(rot(from=UP, to=[(top-bot).x,0,max(0.01,h)], p=[axy.x,0,0]), UP),
if (anch.y!=0) unit(rot(from=UP, to=[0,(top-bot).y,max(0.01,h)], p=[0,axy.y,0]), UP),
if (anch.z!=0) unit([0,0,anch.z],UP)
],
vec2 = anchor==CENTER? UP
Expand Down Expand Up @@ -3385,10 +3389,12 @@ function _find_anchor(anchor, geom) =
size=geom[1], size2=geom[2], shift=geom[3],
u = (anchor.y+1)/2, // 0<=u<=1
frpt = [size.x/2*anchor.x, -size.y/2],
bkpt = [size2/2*anchor.x+shift, size.y/2],
bkpt = [size2/2*anchor.x+shift, size.y/2],
override = geom[4](anchor),
pos = default(override[0],point2d(cp) + lerp(frpt, bkpt, u) + point2d(offset)),
svec = point3d(line_normal(bkpt,frpt)*anchor.x),
pos = override[0] != undef? override[0] :
point2d(cp) + lerp(frpt, bkpt, u) + point2d(offset),
svec = approx(bkpt,frpt)? [anchor.x,0,0] :
point3d(line_normal(bkpt,frpt)*anchor.x),
vec = is_def(override[1]) ? override[1]
: anchor.y == 0? ( anchor.x == 0? BACK : svec )
: anchor.x == 0? [0,anchor.y,0]
Expand All @@ -3398,13 +3404,16 @@ function _find_anchor(anchor, geom) =
let(
anchor = unit(_force_anchor_2d(anchor),[0,0]),
r = force_list(geom[1],2),
pos = approx(anchor.x,0) ? [0,sign(anchor.y)*r.y]
: let(
m = anchor.y/anchor.x,
px = sign(anchor.x) * sqrt(1/(1/sqr(r.x) + m*m/sqr(r.y)))
)
[px,m*px],
vec = unit([r.y/r.x*pos.x, r.x/r.y*pos.y],BACK)
pos = approx(anchor.x,0)
? [0,sign(anchor.y)*r.y]
: let(
m = anchor.y/anchor.x,
px = approx(min(r),0)? 0 :
sign(anchor.x) * sqrt(1/(1/sqr(r.x) + m*m/sqr(r.y)))
)
[px,m*px],
vec = approx(min(r),0)? (approx(norm(anchor),0)? BACK : anchor) :
unit([r.y/r.x*pos.x, r.x/r.y*pos.y],BACK)
) [anchor, point2d(cp+offset)+pos, vec, 0]
) : type == "rgn_isect"? ( //region
let(
Expand Down Expand Up @@ -3594,7 +3603,7 @@ module show_anchors(s=10, std=true, custom=true) {
// Synopsis: Shows a 3d anchor orientation arrow.
// SynTags: Geom
// Topics: Attachments
// See Also: anchor_arrow2d(), show_anchors(), expose_anchors(), frame_ref()
// See Also: anchor_arrow2d(), show_anchors(), expose_anchors(), frame_ref(), generic_airplane()
// Usage:
// anchor_arrow([s], [color], [flag], [anchor=], [orient=], [spin=]) [ATTACHMENTS];
// Description:
Expand Down Expand Up @@ -3635,7 +3644,7 @@ module anchor_arrow(s=10, color=[0.333,0.333,1], flag=true, $tag="anchor-arrow",
// Topics: Attachments
// See Also: anchor_arrow(), show_anchors(), expose_anchors(), frame_ref()
// Usage:
// anchor_arrow2d([s], [color], [flag]);
// anchor_arrow2d([s], [color]);
// Description:
// Show an anchor orientation arrow.
// Arguments:
Expand Down Expand Up @@ -3675,6 +3684,90 @@ module expose_anchors(opacity=0.2) {



// Module: show_transform_list()
// Synopsis: Shows a list of transforms and how they connect.
// SynTags: Geom
// Topics: Attachments
// See Also: generic_airplane(), anchor_arrow(), show_anchors(), expose_anchors(), frame_ref()
// Usage:
// show_transform_list(tlist, [s]);
// show_transform_list(tlist) {CHILDREN};
// Description:
// Given a list of transformation matrices, shows the position and orientation of each one.
// A line is drawn from each transform position to the next one, and an orientation indicator is
// shown at each position. If a child is passed, that child will be used as the orientation indicator.
// By default, a {{generic_airplane()}} is used as the orientation indicator.
// Arguments:
// s = Length of the {{generic_airplane()}}. Default: 5
// Example:
// tlist = [
// zrot(90),
// zrot(90) * fwd(30) * zrot(30),
// zrot(90) * fwd(30) * zrot(30) *
// fwd(35) * xrot(-30),
// zrot(90) * fwd(30) * zrot(30) *
// fwd(35) * xrot(-30) * fwd(40) * yrot(15),
// ];
// show_transform_list(tlist, s=20);
// Example:
// tlist = [
// zrot(90),
// zrot(90) * fwd(30) * zrot(30),
// zrot(90) * fwd(30) * zrot(30) *
// fwd(35) * xrot(-30),
// zrot(90) * fwd(30) * zrot(30) *
// fwd(35) * xrot(-30) * fwd(40) * yrot(15),
// ];
// show_transform_list(tlist) frame_ref();
module show_transform_list(tlist, s=5) {
path = [for (m = tlist) apply(m, [0,0,0])];
stroke(path, width=s*0.03);
for (m = tlist) {
multmatrix(m) {
if ($children>0) children();
else generic_airplane(s=s);
}
}
}


// Module: generic_airplane()
// Synopsis: Shows a generic airplane shape, useful for viewing orientations.
// SynTags: Geom
// Topics: Attachments
// See Also: anchor_arrow(), show_anchors(), expose_anchors(), frame_ref()
// Usage:
// generic_airplane([s]);
// Description:
// Creates a generic airplane shape. This can be useful for viewing the orientation of 3D transforms.
// Arguments:
// s = Length of the airplane. Default: 5
// Example:
// generic_airplane(s=20);
module generic_airplane(s=5) {
$fn = max(segs(0.05*s), 12);
color("#ddd")
fwd(s*0.05)
ycyl(l=0.7*s, d=0.1*s) {
attach(FWD) top_half(s=s) zscale(2) sphere(d=0.1*s);
attach(BACK,FWD) ycyl(l=0.2*s, d1=0.1*s, d2=0.05*s) {
yrot_copies([-90,0,90])
prismoid(s*[0.01,0.2], s*[0.01,0.05],
h=0.2*s, shift=s*[0,0.15], anchor=BOT);
}
yrot_copies([-90,90])
prismoid(s*[0.01,0.2], s*[0.01,0.05],
h=0.5*s, shift=s*[0,0.15], anchor=BOT);
}
color("#777") zcopies(0.1*s) sphere(d=0.02*s);
back(0.09*s) {
color("#f00") right(0.46*s) sphere(d=0.04*s);
color("#0f0") left(0.46*s) sphere(d=0.04*s);
}
}



// Module: frame_ref()
// Synopsis: Shows axis orientation arrows.
// SynTags: Geom
Expand Down
55 changes: 25 additions & 30 deletions distributors.scad
Original file line number Diff line number Diff line change
Expand Up @@ -151,35 +151,34 @@ function move_copies(a=[[0,0,0]],p=_NO_ARG) =
// See Also: move_copies(), ycopies(), zcopies(), line_copies(), grid_copies(), rot_copies(), xrot_copies(), yrot_copies(), zrot_copies(), arc_copies(), sphere_copies()
//
// Usage:
// xcopies(spacing, [n], [sp]) CHILDREN;
// xcopies(l, [n], [sp]) CHILDREN;
// xcopies(spacing, [n], [sp=]) CHILDREN;
// xcopies(l=, [n=], [sp=]) CHILDREN;
// xcopies(LIST) CHILDREN;
// Usage: As a function to translate points, VNF, or Bezier patches
// copies = xcopies(spacing, [n], [sp], p=);
// copies = xcopies(l, [n], [sp], p=);
// copies = xcopies(spacing, [n], [sp=], p=);
// copies = xcopies(l=, [n=], [sp=], p=);
// copies = xcopies(LIST, p=);
// Usage: Get Translation Matrices
// mats = xcopies(spacing, [n], [sp]);
// mats = xcopies(l, [n], [sp]);
// mats = xcopies(spacing, [n], [sp=]);
// mats = xcopies(l=, [n=], [sp=]);
// mats = xcopies(LIST);
// Description:
// When called as a module, places `n` copies of the children along a line on the X axis.
// When called as a function, *without* a `p=` argument, returns a list of transformation matrices, one for each copy.
// When called as a function, *with* a `p=` argument, returns a list of transformed copies of `p=`.
//
// Arguments:
// ---
// 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 place. (Default: 2)
// l = Length to place copies over.
// ---
// l = If given, the length to place copies over.
// sp = If given as a point, copies will be placed on a line to the right of starting position `sp`. If given as a scalar, copies will be placed on a line segment to the right of starting position `[sp,0,0]`. If not given, copies will be placed along a line segment that is centered at [0,0,0].
// p = Either a point, pointlist, VNF or Bezier patch to be translated when used as a function.
//
// 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 index number of each child being copied.
//
//
// Examples:
// xcopies(20) sphere(3);
// xcopies(20, n=3) sphere(3);
Expand Down Expand Up @@ -237,35 +236,34 @@ function xcopies(spacing, n, l, sp, p=_NO_ARG) =
// See Also: move_copies(), xcopies(), zcopies(), line_copies(), grid_copies(), rot_copies(), xrot_copies(), yrot_copies(), zrot_copies(), arc_copies(), sphere_copies()
//
// Usage:
// ycopies(spacing, [n], [sp]) CHILDREN;
// ycopies(l, [n], [sp]) CHILDREN;
// ycopies(spacing, [n], [sp=]) CHILDREN;
// ycopies(l=, [n=], [sp=]) CHILDREN;
// ycopies(LIST) CHILDREN;
// Usage: As a function to translate points, VNF, or Bezier patches
// copies = ycopies(spacing, [n], [sp], p=);
// copies = ycopies(l, [n], [sp], p=);
// copies = ycopies(spacing, [n], [sp=], p=);
// copies = ycopies(l=, [n=], [sp=], p=);
// copies = ycopies(LIST, p=);
// Usage: Get Translation Matrices
// mats = ycopies(spacing, [n], [sp]);
// mats = ycopies(l, [n], [sp]);
// mats = ycopies(spacing, [n], [sp=]);
// mats = ycopies(l=, [n=], [sp=]);
// mats = ycopies(LIST);
// Description:
// When called as a module, places `n` copies of the children along a line on the Y axis.
// When called as a function, *without* a `p=` argument, returns a list of transformation matrices, one for each copy.
// When called as a function, *with* a `p=` argument, returns a list of transformed copies of `p=`.
//
// Arguments:
// ---
// 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 place on the line. (Default: 2)
// l = Length to place copies over.
// ---
// l = If given, the length to place copies over.
// sp = If given as a point, copies will be place on a line back from starting position `sp`. If given as a scalar, copies will be placed on a line back from starting position `[0,sp,0]`. If not given, copies will be placed along a line that is centered at [0,0,0].
// p = Either a point, pointlist, VNF or Bezier patch to be translated when used as a function.
//
// 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 index number of each child being copied.
//
//
// Examples:
// ycopies(20) sphere(3);
// ycopies(20, n=3) sphere(3);
Expand Down Expand Up @@ -323,35 +321,34 @@ function ycopies(spacing, n, l, sp, p=_NO_ARG) =
// See Also: move_copies(), xcopies(), ycopies(), line_copies(), grid_copies(), rot_copies(), xrot_copies(), yrot_copies(), zrot_copies(), arc_copies(), sphere_copies()
//
// Usage:
// zcopies(spacing, [n], [sp]) CHILDREN;
// zcopies(l, [n], [sp]) CHILDREN;
// zcopies(spacing, [n], [sp=]) CHILDREN;
// zcopies(l=, [n=], [sp=]) CHILDREN;
// zcopies(LIST) CHILDREN;
// Usage: As a function to translate points, VNF, or Bezier patches
// copies = zcopies(spacing, [n], [sp], p=);
// copies = zcopies(l, [n], [sp], p=);
// copies = zcopies(spacing, [n], [sp=], p=);
// copies = zcopies(l=, [n=], [sp=], p=);
// copies = zcopies(LIST, p=);
// Usage: Get Translation Matrices
// mats = zcopies(spacing, [n], [sp]);
// mats = zcopies(l, [n], [sp]);
// mats = zcopies(spacing, [n], [sp=]);
// mats = zcopies(l=, [n=], [sp=]);
// mats = zcopies(LIST);
// Description:
// When called as a module, places `n` copies of the children along a line on the Z axis.
// When called as a function, *without* a `p=` argument, returns a list of transformation matrices, one for each copy.
// When called as a function, *with* a `p=` argument, returns a list of transformed copies of `p=`.
//
// Arguments:
// ---
// 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 place. (Default: 2)
// l = Length to place copies over.
// ---
// l = If given, the length to place copies over.
// sp = If given as a point, copies will be placed on a line up from starting position `sp`. If given as a scalar, copies will be placed on a line up from starting position `[0,0,sp]`. If not given, copies will be placed on a line that is centered at [0,0,0].
// p = Either a point, pointlist, VNF or Bezier patch to be translated when used as a function.
//
// 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 index number of each child being copied.
//
//
// Examples:
// zcopies(20) sphere(3);
// zcopies(20, n=3) sphere(3);
Expand Down Expand Up @@ -478,7 +475,6 @@ function zcopies(spacing, n, l, sp, p=_NO_ARG) =
// `$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 index number of each child being copied.
//
//
// Examples:
// line_copies(10) sphere(d=1.5);
// line_copies(10, n=5) sphere(d=3);
Expand Down Expand Up @@ -592,7 +588,6 @@ function line_copies(spacing, n, l, p1, p2, p=_NO_ARG) =
// `$col` is set to the integer column number for each child.
// `$row` is set to the integer row number for each child.
//
//
// Examples:
// grid_copies(size=50, spacing=10) cylinder(d=10, h=1);
// grid_copies(size=50, spacing=[10,15]) cylinder(d=10, h=1);
Expand Down Expand Up @@ -851,7 +846,7 @@ function grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero, p=_
// rot_copies(n=6, v=DOWN+BACK, delta=[20,0,0], subrot=false)
// yrot(90) cylinder(h=20, r1=5, r2=0);
// color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);
module rot_copies(rots=[], v=undef, cp=[0,0,0], n, sa=0, offset=0, delta=[0,0,0], subrot=true)
module rot_copies(rots=[], v, cp=[0,0,0], n, sa=0, offset=0, delta=[0,0,0], subrot=true)
{
req_children($children);
sang = sa + offset;
Expand Down
45 changes: 45 additions & 0 deletions examples/spring_handle.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
include <BOSL2/std.scad>

$fn = 45;
wire_d = 2;
spring_l = 100;
spring_d = 20;
rod_d = 10;
loops = 17;
tight_loops=3;

tpart = tight_loops/loops;
lpart = wire_d * tight_loops / 100;
r_table = [
[0.00, 0],
[0+tpart, 0],
[0.5, 1],
[1-tpart, 0],
[1.00, 0],
];
l_table = [
[0.00, -0.50],
[0+tpart, -0.5+lpart],
[1-tpart, +0.5-lpart],
[1.00, +0.50],
];
lsteps = 45;
tsteps = loops * lsteps;
path = [
for (i = [0:1:tsteps])
let(
u = i / tsteps,
a = u * 360 * loops,
r = lookup(u, r_table) * spring_d/2 + wire_d/2 + rod_d/2,
z = lookup(u, l_table) * spring_l,
pt = [r*cos(a), r*sin(a), z]
) pt
];
yrot(90) {
color("lightblue")
path_sweep(circle(d=wire_d), path);
cylinder(d=rod_d, h=spring_l+10, center=true);
}


// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
Loading

0 comments on commit 7d2b547

Please sign in to comment.