Anchoring bugfixes. Added example to vnf_vertex_array()

This commit is contained in:
Garth Minette 2022-05-12 13:27:34 -07:00
parent ec6b158f8c
commit 64dd55a864
2 changed files with 32 additions and 11 deletions

View File

@ -2045,9 +2045,9 @@ function _find_anchor(anchor, geom) =
vec = unit(v_mul(r,anchor),UP)
) [anchor, pos, vec, oang]
) : type == "vnf_isect"? ( //vnf
let(
vnf=geom[1]
) vnf==EMPTY_VNF? [anchor, [0,0,0], unit(anchor), 0] :
let( vnf=geom[1] )
approx(anchor,CTR)? [anchor, [0,0,0], UP, 0] :
vnf==EMPTY_VNF? [anchor, [0,0,0], unit(anchor), 0] :
let(
eps = 1/2048,
points = vnf[0],
@ -2095,9 +2095,9 @@ function _find_anchor(anchor, geom) =
)
[anchor, pos, n, oang]
) : type == "vnf_extent"? ( //vnf
let(
vnf=geom[1]
) vnf==EMPTY_VNF? [anchor, [0,0,0], unit(anchor), 0] :
let( vnf=geom[1] )
approx(anchor,CTR)? [anchor, [0,0,0], UP, 0] :
vnf==EMPTY_VNF? [anchor, [0,0,0], unit(anchor,UP), 0] :
let(
rpts = apply(rot(from=anchor, to=RIGHT) * move(point3d(-cp)), vnf[0]),
maxx = max(column(rpts,0)),
@ -2144,7 +2144,10 @@ function _find_anchor(anchor, geom) =
) : type == "rgn_isect"? ( //region
let(
anchor = _force_anchor_2d(anchor),
rgn = force_region(move(-point2d(cp), p=geom[1])),
rgn = force_region(move(-point2d(cp), p=geom[1]))
)
approx(anchor,[0,0])? [anchor, [0,0,0], BACK, 0] :
let(
isects = [
for (path=rgn, t=triplet(path,true)) let(
seg1 = [t[0],t[1]],
@ -2166,15 +2169,16 @@ function _find_anchor(anchor, geom) =
vec = unit(isect[2],[0,1])
) [anchor, pos, vec, 0]
) : type == "rgn_extent"? ( //region
let( anchor = _force_anchor_2d(anchor) )
approx(anchor,[0,0])? [anchor, [0,0,0], BACK, 0] :
let(
anchor = _force_anchor_2d(anchor),
rgn = force_region(geom[1]),
rpts = rot(from=anchor, to=RIGHT, p=flatten(rgn)),
maxx = max(column(rpts,0)),
ys = [for (pt=rpts) if (approx(pt.x, maxx)) pt.y],
midy = (min(ys)+max(ys))/2,
pos = rot(from=RIGHT, to=anchor, p=[maxx,midy])
) [anchor, pos, unit(anchor), 0]
) [anchor, pos, unit(anchor,BACK), 0]
) : type=="xrgn_extent" || type=="xrgn_isect" ? ( // extruded region
assert(in_list(anchor.z,[-1,0,1]), "The Z component of an anchor for an extruded 2D shape must be -1, 0, or 1.")
let(
@ -2190,7 +2194,7 @@ function _find_anchor(anchor, geom) =
twmat = zrot(lerp(0, -twist, u)),
mat = shmat * scmat * twmat
)
approx(anchor_xy,[0,0]) ? [anchor, apply(mat, up(anchor.z*L/2,cp)), anchor, oang] :
approx(anchor_xy,[0,0]) ? [anchor, apply(mat, up(anchor.z*L/2,cp)), unit(anchor, UP), oang] :
let(
newrgn = apply(mat, rgn),
newgeom = attach_geom(two_d=true, region=newrgn, extent=type=="xrgn_extent", cp=cp),

View File

@ -104,6 +104,23 @@ EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
// vnf2 = vnf_vertex_array(points=cap1, col_wrap=true);
// vnf3 = vnf_vertex_array(points=cap2, col_wrap=true, reverse=true);
// vnf_polyhedron([vnf1, vnf2, vnf3]);
// Example(3D): Building a Multi-Stage Cylindrical Ramp
// include <BOSL2/rounding.scad>
// major_r = 50;
// groove_profile = [
// [-10,0], each arc(points=[[-7,0],[0,-3],[7,0]]), [10,0]
// ];
// ramp_profile = [ [-10,25], [90,25], [180,5], [190,5] ];
// rgroove = apply(right(major_r) * xrot(90), path3d(groove_profile));
// rprofile = round_corners(ramp_profile, radius=20, closed=false, $fn=72);
// vnf = vnf_vertex_array([
// for (a = [ramp_profile[0].x : 1 : last(ramp_profile).x]) let(
// z = lookup(a,rprofile),
// m = zrot(a) * up(z)
// )
// apply(m, [ [rgroove[0].x,0,-z], each rgroove, [last(rgroove).x,0,-z] ])
// ], caps=true, col_wrap=true, reverse=true);
// vnf_polyhedron(vnf, convexity=8);
function vnf_vertex_array(
points,
caps, cap1, cap2,