mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-30 00:09:37 +00:00
Added cp= to attachable. Added "origin" standard named anchor.
This commit is contained in:
parent
78ecbbd9c5
commit
efa76fe9f5
3 changed files with 84 additions and 67 deletions
139
attachments.scad
139
attachments.scad
|
@ -105,14 +105,14 @@ function anchorpt(name, pos=[0,0,0], orient=UP, spin=0) = [name, pos, orient, sp
|
||||||
// Function: attach_geom()
|
// Function: attach_geom()
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
// geom = attach_geom(anchor, spin, [orient], two_d, size, [size2], [shift], [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], two_d, size, [size2], [shift], [cp], [offset], [anchors]);
|
||||||
// geom = attach_geom(anchor, spin, [orient], two_d, r|d, [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], two_d, r|d, [cp], [offset], [anchors]);
|
||||||
// geom = attach_geom(anchor, spin, [orient], two_d, path, [extent], [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], two_d, path, [extent], [cp], [offset], [anchors]);
|
||||||
// geom = attach_geom(anchor, spin, [orient], size, [size2], [shift], [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], size, [size2], [shift], [cp], [offset], [anchors]);
|
||||||
// geom = attach_geom(anchor, spin, [orient], r|d, l, [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], r|d, l, [cp], [offset], [anchors]);
|
||||||
// geom = attach_geom(anchor, spin, [orient], r1|d1, r2|d2, l, [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], r1|d1, r2|d2, l, [cp], [offset], [anchors]);
|
||||||
// geom = attach_geom(anchor, spin, [orient], r|d, [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], r|d, [cp], [offset], [anchors]);
|
||||||
// geom = attach_geom(anchor, spin, [orient], vnf, [extent], [offset], [anchors]);
|
// geom = attach_geom(anchor, spin, [orient], vnf, [extent], [cp], [offset], [anchors]);
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Given arguments that describe the geometry of an attachable object, returns the internal geometry description.
|
// Given arguments that describe the geometry of an attachable object, returns the internal geometry description.
|
||||||
|
@ -131,7 +131,8 @@ function anchorpt(name, pos=[0,0,0], orient=UP, spin=0) = [name, pos, orient, sp
|
||||||
// vnf = The [VNF](vnf.scad) of the volume.
|
// vnf = The [VNF](vnf.scad) of the volume.
|
||||||
// path = The path to generate a polygon from.
|
// path = The path to generate a polygon from.
|
||||||
// extent = If true, calculate anchors by extents, rather than intersection. Default: true.
|
// extent = If true, calculate anchors by extents, rather than intersection. Default: true.
|
||||||
// offset = If given, offsets the center of the volume.
|
// cp = If given, specifies the centerpoint of the volume. Default: `[0,0,0]`
|
||||||
|
// offset = If given, offsets the perimeter of the volume around the centerpoint.
|
||||||
// anchors = If given as a list of anchor points, allows named anchor points.
|
// anchors = If given as a list of anchor points, allows named anchor points.
|
||||||
// two_d = If true, the attachable shape is 2D. If false, 3D. Default: false (3D)
|
// two_d = If true, the attachable shape is 2D. If false, 3D. Default: false (3D)
|
||||||
//
|
//
|
||||||
|
@ -177,11 +178,13 @@ function attach_geom(
|
||||||
r,r1,r2, d,d1,d2, l,h,
|
r,r1,r2, d,d1,d2, l,h,
|
||||||
vnf, path,
|
vnf, path,
|
||||||
extent=true,
|
extent=true,
|
||||||
|
cp=[0,0,0],
|
||||||
offset=[0,0,0],
|
offset=[0,0,0],
|
||||||
anchors=[],
|
anchors=[],
|
||||||
two_d=false
|
two_d=false
|
||||||
) =
|
) =
|
||||||
assert(is_bool(extent))
|
assert(is_bool(extent))
|
||||||
|
assert(is_vector(cp))
|
||||||
assert(is_vector(offset))
|
assert(is_vector(offset))
|
||||||
assert(is_list(anchors))
|
assert(is_list(anchors))
|
||||||
assert(is_bool(two_d))
|
assert(is_bool(two_d))
|
||||||
|
@ -194,7 +197,7 @@ function attach_geom(
|
||||||
assert(is_vector(size,2))
|
assert(is_vector(size,2))
|
||||||
assert(is_num(size2))
|
assert(is_num(size2))
|
||||||
assert(is_num(shift))
|
assert(is_num(shift))
|
||||||
["rect", point2d(size), size2, shift, offset, anchors]
|
["rect", point2d(size), size2, shift, cp, offset, anchors]
|
||||||
) : (
|
) : (
|
||||||
let(
|
let(
|
||||||
size2 = default(size2, point2d(size)),
|
size2 = default(size2, point2d(size)),
|
||||||
|
@ -203,18 +206,18 @@ function attach_geom(
|
||||||
assert(is_vector(size,3))
|
assert(is_vector(size,3))
|
||||||
assert(is_vector(size2,2))
|
assert(is_vector(size2,2))
|
||||||
assert(is_vector(shift,2))
|
assert(is_vector(shift,2))
|
||||||
["cuboid", size, size2, shift, offset, anchors]
|
["cuboid", size, size2, shift, cp, offset, anchors]
|
||||||
)
|
)
|
||||||
) : !is_undef(vnf)? (
|
) : !is_undef(vnf)? (
|
||||||
assert(is_vnf(vnf))
|
assert(is_vnf(vnf))
|
||||||
assert(two_d == false)
|
assert(two_d == false)
|
||||||
extent? ["vnf_extent", vnf, offset, anchors] :
|
extent? ["vnf_extent", vnf, cp, offset, anchors] :
|
||||||
["vnf_isect", vnf, offset, anchors]
|
["vnf_isect", vnf, cp, offset, anchors]
|
||||||
) : !is_undef(path)? (
|
) : !is_undef(path)? (
|
||||||
assert(is_path(path),2)
|
assert(is_path(path),2)
|
||||||
assert(two_d == true)
|
assert(two_d == true)
|
||||||
extent? ["path_extent", path, offset, anchors] :
|
extent? ["path_extent", path, cp, offset, anchors] :
|
||||||
["path_isect", path, offset, anchors]
|
["path_isect", path, cp, offset, anchors]
|
||||||
) :
|
) :
|
||||||
let(
|
let(
|
||||||
r1 = get_radius(r1=r1,d1=d1,r=r,d=d,dflt=undef)
|
r1 = get_radius(r1=r1,d1=d1,r=r,d=d,dflt=undef)
|
||||||
|
@ -230,14 +233,14 @@ function attach_geom(
|
||||||
assert(is_num(r2) || is_vector(r2,2))
|
assert(is_num(r2) || is_vector(r2,2))
|
||||||
assert(is_num(l))
|
assert(is_num(l))
|
||||||
assert(is_vector(shift,2))
|
assert(is_vector(shift,2))
|
||||||
["cyl", r1, r2, l, shift, offset, anchors]
|
["cyl", r1, r2, l, shift, cp, offset, anchors]
|
||||||
) : (
|
) : (
|
||||||
two_d? (
|
two_d? (
|
||||||
assert(is_num(r1) || is_vector(r1,2))
|
assert(is_num(r1) || is_vector(r1,2))
|
||||||
["circle", r1, offset, anchors]
|
["circle", r1, cp, offset, anchors]
|
||||||
) : (
|
) : (
|
||||||
assert(is_num(r1) || is_vector(r1,3))
|
assert(is_num(r1) || is_vector(r1,3))
|
||||||
["spheroid", r1, offset, anchors]
|
["spheroid", r1, cp, offset, anchors]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) :
|
) :
|
||||||
|
@ -388,18 +391,20 @@ function attach_transform(anchor=CENTER, spin=0, orient=UP, geom, p) =
|
||||||
// geom = The geometry description of the shape.
|
// geom = The geometry description of the shape.
|
||||||
function find_anchor(anchor, geom) =
|
function find_anchor(anchor, geom) =
|
||||||
let(
|
let(
|
||||||
|
cp = select(geom,-3),
|
||||||
offset = anchor==CENTER? CENTER : select(geom,-2),
|
offset = anchor==CENTER? CENTER : select(geom,-2),
|
||||||
anchors = select(geom,-1),
|
anchors = select(geom,-1),
|
||||||
type = geom[0]
|
type = geom[0]
|
||||||
)
|
)
|
||||||
is_string(anchor)? (
|
is_string(anchor)? (
|
||||||
|
anchor=="origin"? [anchor, CENTER, UP, 0] :
|
||||||
let(found = search([anchor], anchors, num_returns_per_match=1)[0])
|
let(found = search([anchor], anchors, num_returns_per_match=1)[0])
|
||||||
assert(found!=[], str("Unknown anchor: ",anchor))
|
assert(found!=[], str("Unknown anchor: ",anchor))
|
||||||
anchors[found]
|
anchors[found]
|
||||||
) :
|
) :
|
||||||
assert(is_vector(anchor),str("anchor=",anchor))
|
assert(is_vector(anchor),str("anchor=",anchor))
|
||||||
let(anchor = point3d(anchor))
|
let(anchor = point3d(anchor))
|
||||||
anchor==CENTER? [anchor, CENTER, UP, 0] :
|
anchor==CENTER? [anchor, cp, UP, 0] :
|
||||||
let(
|
let(
|
||||||
oang = (
|
oang = (
|
||||||
approx(point2d(anchor), [0,0])? 0 :
|
approx(point2d(anchor), [0,0])? 0 :
|
||||||
|
@ -414,9 +419,9 @@ function find_anchor(anchor, geom) =
|
||||||
axy = point2d(anchor),
|
axy = point2d(anchor),
|
||||||
bot = point3d(vmul(point2d(size)/2,axy),-h/2),
|
bot = point3d(vmul(point2d(size)/2,axy),-h/2),
|
||||||
top = point3d(vmul(point2d(size2)/2,axy)+shift,h/2),
|
top = point3d(vmul(point2d(size2)/2,axy)+shift,h/2),
|
||||||
pos = lerp(bot,top,u)+offset,
|
pos = point3d(cp) + lerp(bot,top,u) + offset,
|
||||||
sidevec = unit(rot(from=UP, to=top-bot, p=point3d(axy))),
|
sidevec = unit(rot(from=UP, to=top-bot, p=point3d(axy))),
|
||||||
vvec = unit([0,0,anchor.z]),
|
vvec = anchor==CENTER? UP : unit([0,0,anchor.z]),
|
||||||
vec = anchor==CENTER? UP :
|
vec = anchor==CENTER? UP :
|
||||||
approx(axy,[0,0])? unit(anchor) :
|
approx(axy,[0,0])? unit(anchor) :
|
||||||
approx(anchor.z,0)? sidevec :
|
approx(anchor.z,0)? sidevec :
|
||||||
|
@ -431,9 +436,9 @@ function find_anchor(anchor, geom) =
|
||||||
axy = unit(point2d(anchor)),
|
axy = unit(point2d(anchor)),
|
||||||
bot = point3d(vmul(r1,axy), -l/2),
|
bot = point3d(vmul(r1,axy), -l/2),
|
||||||
top = point3d(vmul(r2,axy)+shift, l/2),
|
top = point3d(vmul(r2,axy)+shift, l/2),
|
||||||
pos = lerp(bot,top,u)+offset,
|
pos = point3d(cp) + lerp(bot,top,u) + offset,
|
||||||
sidevec = rot(from=UP, to=top-bot, p=point3d(axy)),
|
sidevec = rot(from=UP, to=top-bot, p=point3d(axy)),
|
||||||
vvec = unit([0,0,anchor.z]),
|
vvec = anchor==CENTER? UP : unit([0,0,anchor.z]),
|
||||||
vec = anchor==CENTER? UP :
|
vec = anchor==CENTER? UP :
|
||||||
approx(axy,[0,0])? unit(anchor) :
|
approx(axy,[0,0])? unit(anchor) :
|
||||||
approx(anchor.z,0)? sidevec :
|
approx(anchor.z,0)? sidevec :
|
||||||
|
@ -443,16 +448,20 @@ function find_anchor(anchor, geom) =
|
||||||
let(
|
let(
|
||||||
rr = geom[1],
|
rr = geom[1],
|
||||||
r = is_num(rr)? [rr,rr,rr] : rr,
|
r = is_num(rr)? [rr,rr,rr] : rr,
|
||||||
anchor = unit(point3d(anchor))
|
anchor = unit(point3d(anchor)),
|
||||||
) [anchor, vmul(r,anchor)+offset, unit(vmul(r,anchor)), oang]
|
pos = point3d(cp) + vmul(r,anchor) + offset,
|
||||||
|
vec = unit(vmul(r,anchor))
|
||||||
|
) [anchor, pos, vec, oang]
|
||||||
) : type == "vnf_isect"? ( //vnf
|
) : type == "vnf_isect"? ( //vnf
|
||||||
let(
|
let(
|
||||||
vnf=geom[1],
|
vnf=geom[1],
|
||||||
eps = 1/2048,
|
eps = 1/2048,
|
||||||
rpts = rot(from=anchor, to=RIGHT, p=vnf[0]),
|
points = vnf[0],
|
||||||
|
faces = vnf[1],
|
||||||
|
rpts = rot(from=anchor, to=RIGHT, p=move(point3d(-cp), p=points)),
|
||||||
hits = [
|
hits = [
|
||||||
for (i = idx(vnf[1])) let(
|
for (i = idx(faces)) let(
|
||||||
face = vnf[1][i],
|
face = faces[i],
|
||||||
verts = select(rpts, face)
|
verts = select(rpts, face)
|
||||||
) if (
|
) if (
|
||||||
max(subindex(verts,0)) >= -eps &&
|
max(subindex(verts,0)) >= -eps &&
|
||||||
|
@ -462,22 +471,22 @@ function find_anchor(anchor, geom) =
|
||||||
min(subindex(verts,2)) <= eps
|
min(subindex(verts,2)) <= eps
|
||||||
) let(
|
) let(
|
||||||
pt = polygon_line_intersection(
|
pt = polygon_line_intersection(
|
||||||
select(vnf[0], face),
|
select(points, face),
|
||||||
[CENTER,anchor], eps=eps
|
[CENTER,anchor], eps=eps
|
||||||
)
|
)
|
||||||
) if (!is_undef(pt)) [norm(pt),i,pt]
|
) if (!is_undef(pt)) [norm(pt), i, pt]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert(len(hits)>0, "Anchor vector does not intersect with the shape. Attachment failed.")
|
assert(len(hits)>0, "Anchor vector does not intersect with the shape. Attachment failed.")
|
||||||
let(
|
let(
|
||||||
furthest = max_index(subindex(hits,0)),
|
furthest = max_index(subindex(hits,0)),
|
||||||
pos = hits[furthest][2],
|
pos = point3d(cp) + hits[furthest][2],
|
||||||
dist = hits[furthest][0],
|
dist = hits[furthest][0],
|
||||||
nfaces = [for (hit = hits) if(approx(hit[0],dist,eps=eps)) hit[1]],
|
nfaces = [for (hit = hits) if(approx(hit[0],dist,eps=eps)) hit[1]],
|
||||||
n = unit(
|
n = unit(
|
||||||
sum([
|
sum([
|
||||||
for (i = nfaces) let(
|
for (i = nfaces) let(
|
||||||
faceverts = select(vnf[0],vnf[1][i]),
|
faceverts = select(points, faces[i]),
|
||||||
faceplane = plane_from_points(faceverts),
|
faceplane = plane_from_points(faceverts),
|
||||||
nrm = plane_normal(faceplane)
|
nrm = plane_normal(faceplane)
|
||||||
) nrm
|
) nrm
|
||||||
|
@ -488,14 +497,14 @@ function find_anchor(anchor, geom) =
|
||||||
) : type == "vnf_extent"? ( //vnf
|
) : type == "vnf_extent"? ( //vnf
|
||||||
let(
|
let(
|
||||||
vnf=geom[1],
|
vnf=geom[1],
|
||||||
rpts = rot(from=anchor, to=RIGHT, p=vnf[0]),
|
rpts = rot(from=anchor, to=RIGHT, p=move(point3d(-cp), p=vnf[0])),
|
||||||
maxx = max(subindex(rpts,0)),
|
maxx = max(subindex(rpts,0)),
|
||||||
idxs = [for (i = idx(rpts)) if (approx(rpts[i].x, maxx)) i],
|
idxs = [for (i = idx(rpts)) if (approx(rpts[i].x, maxx)) i],
|
||||||
mm = pointlist_bounds(select(rpts,idxs)),
|
mm = pointlist_bounds(select(rpts,idxs)),
|
||||||
avgy = (mm[0].y+mm[1].y)/2,
|
avgy = (mm[0].y+mm[1].y)/2,
|
||||||
avgz = (mm[0].z+mm[1].z)/2,
|
avgz = (mm[0].z+mm[1].z)/2,
|
||||||
mpt = approx(point2d(anchor),[0,0])? [maxx,0,0] : [maxx, avgy, avgz],
|
mpt = approx(point2d(anchor),[0,0])? [maxx,0,0] : [maxx, avgy, avgz],
|
||||||
pos = rot(from=RIGHT, to=anchor, p=mpt)
|
pos = point3d(cp) + rot(from=RIGHT, to=anchor, p=mpt)
|
||||||
) [anchor, pos, anchor, oang]
|
) [anchor, pos, anchor, oang]
|
||||||
) : type == "rect"? ( //size, size2
|
) : type == "rect"? ( //size, size2
|
||||||
let(
|
let(
|
||||||
|
@ -503,18 +512,20 @@ function find_anchor(anchor, geom) =
|
||||||
u = (anchor.y+1)/2,
|
u = (anchor.y+1)/2,
|
||||||
frpt = [size.x/2*anchor.x, -size.y/2],
|
frpt = [size.x/2*anchor.x, -size.y/2],
|
||||||
bkpt = [size2/2*anchor.x, size.y/2],
|
bkpt = [size2/2*anchor.x, size.y/2],
|
||||||
pos = lerp(frpt, bkpt, u),
|
pos = point2d(cp) + lerp(frpt, bkpt, u) + offset,
|
||||||
vec = unit(rot(from=BACK, to=bkpt-frpt, p=anchor))
|
vec = unit(rot(from=BACK, to=bkpt-frpt, p=anchor))
|
||||||
) [anchor, pos, vec, 0]
|
) [anchor, pos, vec, 0]
|
||||||
) : type == "circle"? ( //r
|
) : type == "circle"? ( //r
|
||||||
let(
|
let(
|
||||||
rr = geom[1],
|
rr = geom[1],
|
||||||
r = is_num(rr)? [rr,rr] : rr,
|
r = is_num(rr)? [rr,rr] : rr,
|
||||||
anchor = unit(point2d(anchor))
|
pos = point2d(cp) + vmul(r,anchor) + offset,
|
||||||
) [anchor, vmul(r,anchor)+offset, unit(vmul([r.y,r.x],anchor)), 0]
|
anchor = unit(point2d(anchor)),
|
||||||
|
vec = unit(vmul([r.y,r.x],anchor))
|
||||||
|
) [anchor, pos, vec, 0]
|
||||||
) : type == "path_isect"? ( //path
|
) : type == "path_isect"? ( //path
|
||||||
let(
|
let(
|
||||||
path=geom[1],
|
path = move(-point2d(cp), p=geom[1]),
|
||||||
anchor = point2d(anchor),
|
anchor = point2d(anchor),
|
||||||
isects = [
|
isects = [
|
||||||
for (t=triplet_wrap(path)) let(
|
for (t=triplet_wrap(path)) let(
|
||||||
|
@ -530,20 +541,20 @@ function find_anchor(anchor, geom) =
|
||||||
],
|
],
|
||||||
maxidx = max_index(subindex(isects,0)),
|
maxidx = max_index(subindex(isects,0)),
|
||||||
isect = isects[maxidx],
|
isect = isects[maxidx],
|
||||||
pos = isect[1],
|
pos = point2d(cp) + isect[1],
|
||||||
vec = unit(isect[2])
|
vec = unit(isect[2])
|
||||||
) [anchor, pos, vec, 0]
|
) [anchor, pos, vec, 0]
|
||||||
) : type == "path_extent"? ( //path
|
) : type == "path_extent"? ( //path
|
||||||
let(
|
let(
|
||||||
path=geom[1],
|
path = geom[1],
|
||||||
anchor = point2d(anchor),
|
anchor = point2d(anchor),
|
||||||
rpath = rot(from=anchor, to=RIGHT, p=path),
|
rpath = rot(from=anchor, to=RIGHT, p=move(point2d(-cp), p=path)),
|
||||||
maxx = max(subindex(rpath,0)),
|
maxx = max(subindex(rpath,0)),
|
||||||
idxs = [for (i = idx(rpath)) if (approx(rpath[i].x, maxx)) i],
|
idxs = [for (i = idx(rpath)) if (approx(rpath[i].x, maxx)) i],
|
||||||
miny = min([for (i=idxs) rpath[i].y]),
|
miny = min([for (i=idxs) rpath[i].y]),
|
||||||
maxy = max([for (i=idxs) rpath[i].y]),
|
maxy = max([for (i=idxs) rpath[i].y]),
|
||||||
avgy = (miny+maxy)/2,
|
avgy = (miny+maxy)/2,
|
||||||
pos = rot(from=RIGHT, to=anchor, p=[maxx,avgy])
|
pos = point2d(cp) + rot(from=RIGHT, to=anchor, p=[maxx,avgy])
|
||||||
) [anchor, pos, anchor, 0]
|
) [anchor, pos, anchor, 0]
|
||||||
) :
|
) :
|
||||||
assert(false, "Unknown attachment geometry type.");
|
assert(false, "Unknown attachment geometry type.");
|
||||||
|
@ -567,14 +578,14 @@ function attachment_is_shown(tags) =
|
||||||
// Function: reorient()
|
// Function: reorient()
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
// reorient(anchor, spin, [orient], two_d, size, [size2], [shift], [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], two_d, size, [size2], [shift], [cp], [offset], [anchors], [p]);
|
||||||
// reorient(anchor, spin, [orient], two_d, r|d, [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], two_d, r|d, [cp], [offset], [anchors], [p]);
|
||||||
// reorient(anchor, spin, [orient], two_d, path, [extent], [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], two_d, path, [extent], [cp], [offset], [anchors], [p]);
|
||||||
// reorient(anchor, spin, [orient], size, [size2], [shift], [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], size, [size2], [shift], [cp], [offset], [anchors], [p]);
|
||||||
// reorient(anchor, spin, [orient], r|d, l, [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], r|d, l, [offset], [cp], [anchors], [p]);
|
||||||
// reorient(anchor, spin, [orient], r1|d1, r2|d2, l, [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], r1|d1, r2|d2, l, [cp], [offset], [anchors], [p]);
|
||||||
// reorient(anchor, spin, [orient], r|d, [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], r|d, [cp], [offset], [anchors], [p]);
|
||||||
// reorient(anchor, spin, [orient], vnf, [extent], [offset], [anchors], [p]);
|
// reorient(anchor, spin, [orient], vnf, [extent], [cp], [offset], [anchors], [p]);
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Given anchor, spin, orient, and general geometry info for a managed volume, this calculates
|
// Given anchor, spin, orient, and general geometry info for a managed volume, this calculates
|
||||||
|
@ -615,7 +626,8 @@ function attachment_is_shown(tags) =
|
||||||
// vnf = The [VNF](vnf.scad) of the volume.
|
// vnf = The [VNF](vnf.scad) of the volume.
|
||||||
// path = The path to generate a polygon from.
|
// path = The path to generate a polygon from.
|
||||||
// extent = If true, calculate anchors by extents, rather than intersection. Default: false.
|
// extent = If true, calculate anchors by extents, rather than intersection. Default: false.
|
||||||
// offset = If given, offsets the center of the volume.
|
// cp = If given, specifies the centerpoint of the volume. Default: `[0,0,0]`
|
||||||
|
// offset = If given, offsets the perimeter of the volume around the centerpoint.
|
||||||
// anchors = If given as a list of anchor points, allows named anchor points.
|
// anchors = If given as a list of anchor points, allows named anchor points.
|
||||||
// two_d = If true, the attachable shape is 2D. If false, 3D. Default: false (3D)
|
// two_d = If true, the attachable shape is 2D. If false, 3D. Default: false (3D)
|
||||||
// p = The VNF, path, or point to transform.
|
// p = The VNF, path, or point to transform.
|
||||||
|
@ -628,6 +640,7 @@ function reorient(
|
||||||
vnf, path,
|
vnf, path,
|
||||||
extent=true,
|
extent=true,
|
||||||
offset=[0,0,0],
|
offset=[0,0,0],
|
||||||
|
cp=[0,0,0],
|
||||||
anchors=[],
|
anchors=[],
|
||||||
two_d=false,
|
two_d=false,
|
||||||
p=undef
|
p=undef
|
||||||
|
@ -637,7 +650,7 @@ function reorient(
|
||||||
r=r, r1=r1, r2=r2, h=h,
|
r=r, r1=r1, r2=r2, h=h,
|
||||||
d=d, d1=d1, d2=d2, l=l,
|
d=d, d1=d1, d2=d2, l=l,
|
||||||
vnf=vnf, path=path, extent=extent,
|
vnf=vnf, path=path, extent=extent,
|
||||||
offset=offset, anchors=anchors,
|
cp=cp, offset=offset, anchors=anchors,
|
||||||
two_d=two_d
|
two_d=two_d
|
||||||
),
|
),
|
||||||
$attach_to = undef
|
$attach_to = undef
|
||||||
|
@ -650,14 +663,14 @@ function reorient(
|
||||||
// Module: attachable()
|
// Module: attachable()
|
||||||
//
|
//
|
||||||
// Usage:
|
// Usage:
|
||||||
// attachable(anchor, spin, [orient], two_d, size, [size2], [shift], [offset], [anchors] ...
|
// attachable(anchor, spin, [orient], two_d, size, [size2], [shift], [cp], [offset], [anchors] ...
|
||||||
// attachable(anchor, spin, [orient], two_d, r|d, [offset], [anchors]) ...
|
// attachable(anchor, spin, [orient], two_d, r|d, [cp], [offset], [anchors]) ...
|
||||||
// attachable(anchor, spin, [orient], two_d, path, [extent], [offset], [anchors] ...
|
// attachable(anchor, spin, [orient], two_d, path, [extent], [cp], [offset], [anchors] ...
|
||||||
// attachable(anchor, spin, [orient], size, [size2], [shift], [offset], [anchors] ...
|
// attachable(anchor, spin, [orient], size, [size2], [shift], [cp], [offset], [anchors] ...
|
||||||
// attachable(anchor, spin, [orient], r|d, l, [offset], [anchors]) ...
|
// attachable(anchor, spin, [orient], r|d, l, [cp], [offset], [anchors]) ...
|
||||||
// attachable(anchor, spin, [orient], r1|d1, r2|d2, l, [offset], [anchors]) ...
|
// attachable(anchor, spin, [orient], r1|d1, r2|d2, l, [cp], [offset], [anchors]) ...
|
||||||
// attachable(anchor, spin, [orient], r|d, [offset], [anchors]) ...
|
// attachable(anchor, spin, [orient], r|d, [cp], [offset], [anchors]) ...
|
||||||
// attachable(anchor, spin, [orient], vnf, [extent], [offset], [anchors]) ...
|
// attachable(anchor, spin, [orient], vnf, [extent], [cp], [offset], [anchors]) ...
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Manages the anchoring, spin, orientation, and attachments for a 3D volume or 2D area.
|
// Manages the anchoring, spin, orientation, and attachments for a 3D volume or 2D area.
|
||||||
|
@ -703,7 +716,8 @@ function reorient(
|
||||||
// vnf = The [VNF](vnf.scad) of the volume.
|
// vnf = The [VNF](vnf.scad) of the volume.
|
||||||
// path = The path to generate a polygon from.
|
// path = The path to generate a polygon from.
|
||||||
// extent = If true, calculate anchors by extents, rather than intersection. Default: false.
|
// extent = If true, calculate anchors by extents, rather than intersection. Default: false.
|
||||||
// offset = If given, offsets the center of the volume.
|
// cp = If given, specifies the centerpoint of the volume. Default: `[0,0,0]`
|
||||||
|
// offset = If given, offsets the perimeter of the volume around the centerpoint.
|
||||||
// anchors = If given as a list of anchor points, allows named anchor points.
|
// anchors = If given as a list of anchor points, allows named anchor points.
|
||||||
// two_d = If true, the attachable shape is 2D. If false, 3D. Default: false (3D)
|
// two_d = If true, the attachable shape is 2D. If false, 3D. Default: false (3D)
|
||||||
//
|
//
|
||||||
|
@ -791,6 +805,7 @@ module attachable(
|
||||||
r,r1,r2, d,d1,d2, l,h,
|
r,r1,r2, d,d1,d2, l,h,
|
||||||
vnf, path,
|
vnf, path,
|
||||||
extent=true,
|
extent=true,
|
||||||
|
cp=[0,0,0],
|
||||||
offset=[0,0,0],
|
offset=[0,0,0],
|
||||||
anchors=[],
|
anchors=[],
|
||||||
two_d=false
|
two_d=false
|
||||||
|
@ -804,7 +819,7 @@ module attachable(
|
||||||
r=r, r1=r1, r2=r2, h=h,
|
r=r, r1=r1, r2=r2, h=h,
|
||||||
d=d, d1=d1, d2=d2, l=l,
|
d=d, d1=d1, d2=d2, l=l,
|
||||||
vnf=vnf, path=path, extent=extent,
|
vnf=vnf, path=path, extent=extent,
|
||||||
offset=offset, anchors=anchors,
|
cp=cp, offset=offset, anchors=anchors,
|
||||||
two_d=two_d
|
two_d=two_d
|
||||||
);
|
);
|
||||||
m = attach_transform(anchor,spin,orient,geom);
|
m = attach_transform(anchor,spin,orient,geom);
|
||||||
|
|
10
regions.scad
10
regions.scad
|
@ -337,15 +337,17 @@ function region_faces(region, transform, reverse=false, vnf=EMPTY_VNF) =
|
||||||
// mrgn = union(rgn1,rgn2);
|
// mrgn = union(rgn1,rgn2);
|
||||||
// orgn = difference(mrgn,rgn3);
|
// orgn = difference(mrgn,rgn3);
|
||||||
// linear_sweep(orgn,height=20,convexity=16) show_anchors();
|
// linear_sweep(orgn,height=20,convexity=16) show_anchors();
|
||||||
module linear_sweep(region, height=1, center=false, twist=0, scale=1, slices, maxseg, style="default", convexity, anchor_isect=false, anchor=BOT, spin=0, orient=UP) {
|
module linear_sweep(region, height=1, center, twist=0, scale=1, slices, maxseg, style="default", convexity, anchor_isect=false, anchor, spin=0, orient=UP) {
|
||||||
anchor = get_anchor(anchor, center, BOT, BOT);
|
region = is_path(region)? [region] : region;
|
||||||
|
cp = median(flatten(region));
|
||||||
|
anchor = get_anchor(anchor, center, "origin", "origin");
|
||||||
vnf = linear_sweep(
|
vnf = linear_sweep(
|
||||||
region, height=height,
|
region, height=height,
|
||||||
twist=twist, scale=scale,
|
twist=twist, scale=scale,
|
||||||
slices=slices, maxseg=maxseg,
|
slices=slices, maxseg=maxseg,
|
||||||
style=style
|
style=style
|
||||||
);
|
);
|
||||||
attachable(anchor,spin,orient, vnf=vnf, extent=!anchor_isect) {
|
attachable(anchor,spin,orient, cp=cp, vnf=vnf, extent=!anchor_isect) {
|
||||||
vnf_polyhedron(vnf, convexity=convexity);
|
vnf_polyhedron(vnf, convexity=convexity);
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
@ -355,10 +357,10 @@ module linear_sweep(region, height=1, center=false, twist=0, scale=1, slices, ma
|
||||||
function linear_sweep(region, height=1, twist=0, scale=1, slices, maxseg, style="default") =
|
function linear_sweep(region, height=1, twist=0, scale=1, slices, maxseg, style="default") =
|
||||||
let(
|
let(
|
||||||
region = is_path(region)? [region] : region,
|
region = is_path(region)? [region] : region,
|
||||||
|
regions = split_nested_region(region),
|
||||||
slices = default(slices, floor(twist/5+1)),
|
slices = default(slices, floor(twist/5+1)),
|
||||||
step = twist/slices,
|
step = twist/slices,
|
||||||
hstep = height/slices,
|
hstep = height/slices,
|
||||||
regions = split_nested_region(region),
|
|
||||||
trgns = [
|
trgns = [
|
||||||
for (rgn=regions) [
|
for (rgn=regions) [
|
||||||
for (path=rgn) let(
|
for (path=rgn) let(
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,383];
|
BOSL_VERSION = [2,0,384];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue