improved thread_helix docs

fixed bugs in spiral_sweep: wrong sampling rate, left_handed broken
This commit is contained in:
Adrian Mariano 2021-08-28 08:57:09 -04:00
parent 352436938f
commit 6ef2f71255
2 changed files with 30 additions and 16 deletions

View file

@ -1055,7 +1055,7 @@ module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) {
// spiral_sweep(poly, h=200, r=50, twist=1080, $fn=36); // spiral_sweep(poly, h=200, r=50, twist=1080, $fn=36);
module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, higbee1, higbee2, internal=false, anchor, spin=0, orient=UP) { module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, higbee1, higbee2, internal=false, anchor, spin=0, orient=UP) {
higsample = 10; // Oversample factor for higbee tapering higsample = 10; // Oversample factor for higbee tapering
dummy1=assert(twist>0); // dummy1=assert(twist>0);
bounds = pointlist_bounds(poly); bounds = pointlist_bounds(poly);
yctr = (bounds[0].y+bounds[1].y)/2; yctr = (bounds[0].y+bounds[1].y)/2;
xmin = bounds[0].x; xmin = bounds[0].x;
@ -1065,7 +1065,8 @@ module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, hi
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=50); r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=50);
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=50); r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=50);
sides = segs(max(r1,r2)); sides = segs(max(r1,r2));
ang_step = 360/sides; dir = sign(twist);
ang_step = 360/sides*dir;
anglist = [for(ang = [0:ang_step:twist-EPSILON]) ang, anglist = [for(ang = [0:ang_step:twist-EPSILON]) ang,
twist]; twist];
higbee1 = first_defined([higbee1, higbee, 0]); higbee1 = first_defined([higbee1, higbee, 0]);
@ -1073,23 +1074,24 @@ module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, hi
higang1 = 360 * higbee1 / (2 * r1 * PI); higang1 = 360 * higbee1 / (2 * r1 * PI);
higang2 = 360 * higbee2 / (2 * r2 * PI); higang2 = 360 * higbee2 / (2 * r2 * PI);
dummy2=assert(higbee1>=0 && higbee2>=0) dummy2=assert(higbee1>=0 && higbee2>=0)
assert(higang1 < twist/2) assert(higang1 < dir*twist/2)
assert(higang2 < twist/2); assert(higang2 < dir*twist/2);
function polygon_r(N,theta) = function polygon_r(N,theta) =
let( alpha = 360/N ) let( alpha = 360/N )
cos(alpha/2)/(cos(posmod(theta,alpha)-alpha/2)); cos(alpha/2)/(cos(posmod(theta,alpha)-alpha/2));
function higsize(a) = lookup(a,[ function higsize(a) = lookup(a,[
[-0.001, higang1>0?0:1], [-0.001*dir, higang1>0?0:1],
if (higang1>0) for (x=[0.125:0.125:1]) [ x*higang1, pow(x,1/2)], if (higang1>0) for (x=[0.125:0.125:1]) [ dir*x*higang1, pow(x,1/2)],
if (higang2>0) for (x=[0.125:0.125:1]) [twist-x*higang2, pow(x,1/2)], if (higang2>0) for (x=[0.125:0.125:1]) [twist-dir*x*higang2, pow(x,1/2)],
[twist+0.001, higang2>0?0:1] [twist+dir*0.001, higang2>0?0:1]
]); ]);
interp_ang = [ interp_ang = [
for(i=idx(anglist,e=-2)) for(i=idx(anglist,e=-2))
each lerpn(anglist[i],anglist[i+1], each lerpn(anglist[i],anglist[i+1],
(higang1<anglist[i+1] || (twist-higang2>anglist[i])) ? ceil((anglist[i+1]-anglist[i])/ang_step*higsample) (higang1>0 && higang1>dir*anglist[i+1]
: 1, || (higang2>0 && higang2>dir*(twist-anglist[i]))) ? ceil((anglist[i+1]-anglist[i])/ang_step*higsample)
: 1,
endpoint=false), endpoint=false),
last(anglist) last(anglist)
]; ];
@ -1110,12 +1112,12 @@ module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, hi
]; ];
vnf = vnf_vertex_array( vnf = vnf_vertex_array(
points, col_wrap=true, caps=true, reverse=true, points, col_wrap=true, caps=true, reverse=dir>0?true:false,
style=higbee1>0 || higbee2>0 ? "quincunx" : "alt" style=higbee1>0 || higbee2>0 ? "quincunx" : "alt"
); );
attachable(anchor,spin,orient, r1=r1, r2=r2, l=h) { attachable(anchor,spin,orient, r1=r1, r2=r2, l=h) {
vnf_polyhedron(vnf, convexity=ceil(2*twist/360)); vnf_polyhedron(vnf, convexity=ceil(2*dir*twist/360));
children(); children();
} }
} }

View file

@ -1093,14 +1093,23 @@ module generic_threaded_nut(
// Description: // Description:
// Creates a right-handed helical thread with optional end tapering. Unlike generic_threaded_rod, this module just generates the thread, and // Creates a right-handed helical thread with optional end tapering. Unlike generic_threaded_rod, this module just generates the thread, and
// you specify the angle of thread you want, which makes it easy to put complete threads onto a longer shaft. It also makes a more finely // you specify the angle of thread you want, which makes it easy to put complete threads onto a longer shaft. It also makes a more finely
// divided taper at the thread ends. However, if you use it for large length of thread it is much slower than generic_threaded_rod. // divided taper at the thread ends. However, it takes about twice as long to render compared to generic_threaded_rod.
// . // .
// You can specify a thread_depth and flank_angle, in which // You can specify a thread_depth and flank_angle, in which
// case you get a symmetric trapezoidal thread, whose base is at the diameter (so the total diameter will be d + thread_depth). // case you get a symmetric trapezoidal thread, whose inner diameter (the base of the threads for external threading)
// Atlernatively you can give a profile, following the same rules as for general_threaded_rod. // is d (so the total diameter will be d + thread_depth). This differs from the threaded_rod modules, where the specified
// diameter is the outer diameter.
// Alternatively you can give a profile, following the same rules as for general_threaded_rod.
// The Y=0 point will align with the specified diameter, and the profile should // The Y=0 point will align with the specified diameter, and the profile should
// range in X from -1/2 to 1/2. You cannot specify both the profile and the thread_depth or flank_angle. // range in X from -1/2 to 1/2. You cannot specify both the profile and the thread_depth or flank_angle.
// . // .
// Unlike generic_threaded_rod, when internal=true this module generates the threads, not a thread mask.
// The profile needs to be inverted to produce the proper thread form. If you use the built-in trapezoidal
// thread you get the inverted thread, designed so that the inner diameter is d. With adequate clearance
// this thread will mate with the thread that uses the same parameters but has internal=false. Note that
// unlike the threaded_rod modules, thread_helix does not adjust the diameter for faceting, nor does it
// subtract any $slop for clearance.
// .
// Higbee specifies tapering applied to the ends of the threads and is given as the linear distance // Higbee specifies tapering applied to the ends of the threads and is given as the linear distance
// over which to taper. // over which to taper.
// Arguments: // Arguments:
@ -1134,6 +1143,9 @@ module generic_threaded_nut(
// stroke(profile, width=0.02); // stroke(profile, width=0.02);
// Example: // Example:
// thread_helix(d=10, pitch=2, thread_depth=0.75, flank_angle=15, twist=900, $fn=72); // thread_helix(d=10, pitch=2, thread_depth=0.75, flank_angle=15, twist=900, $fn=72);
// thread_helix(d=10, pitch=2, thread_depth=0.75, flank_angle=15, twist=900, higbee=1, $fn=72);
// thread_helix(d=10, pitch=2, thread_depth=0.75, flank_angle=15, twist=720, higbee=2, internal=true, $fn=72);
// thread_helix(d=10, pitch=2, thread_depth=0.75, flank_angle=15, twist=360, left_handed=true, higbee=1, $fn=36);
module thread_helix( module thread_helix(
d, pitch, thread_depth, flank_angle, twist=720, d, pitch, thread_depth, flank_angle, twist=720,
profile, starts=1, left_handed=false, internal=false, profile, starts=1, left_handed=false, internal=false,