internal: can set bevel to true and get non-garbage result

bevel is always set by thread depth
   acme takes tpi
   square threads are at angle 0
   added generic_threaded_{rod,nut}
   eliminated metric_trapezoidal_*
   cleaned up matrices some in generic_threaded_rod
   threaded_rod can produce spec-true ISO/UTS profile with a triplet input for the diameter.
   Added bevel1 and bevel2 to all modules.  Made default uniformly false for every case instead of
       sometimes true, sometimes false
   Profiles that go over zero are not clipped, and bevels are based on actual profile top, not nominal
   When bevel is given to nuts it bevels the outside of the nut by thread depth
   higbee looks best with quincunx, but it's more expensive.  Select quincunx when higbee is used, min_edge otherwise
   Current code uses difference to remove excess length in the rod.  This gives faster renders at the cost
      of more complex code and green top/bottom surfaces.
   Changed slop to 4 * $slop.  I got good results printing with $slop=0.05 with this setting.
   Don't generate excess threads when starts>1, and don't force threads to be even
This commit is contained in:
Adrian Mariano
2021-08-22 21:53:08 -04:00
parent 5cd0b5d03c
commit ce0b4e9d32
4 changed files with 734 additions and 499 deletions

View File

@@ -1040,6 +1040,9 @@ module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) {
// ---
// d = Diameter of the spiral to extrude along.
// higbee = Length to taper thread ends over.
// higbee1 = Taper length at start
// higbee2 = Taper length at end
// internal = direction to taper the threads with higbee. Default: false
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
@@ -1047,7 +1050,11 @@ module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) {
// Example:
// poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]];
// 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, 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) {
bounds = pointlist_bounds(poly);
yctr = (bounds[0].y+bounds[1].y)/2;
xmin = bounds[0].x;
xmax = bounds[1].x;
poly = path3d(poly);
anchor = get_anchor(anchor,center,BOT,BOT);
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=50);
@@ -1062,7 +1069,6 @@ module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, hi
higsteps2 = ceil(higang2/360*sides);
assert(higang1 < twist/2);
assert(higang2 < twist/2);
function higsize(a) = lookup(a,[
[-0.001, 0],
for (x=[0.125:0.125:1]) [ x*higang1, pow(x,1/2)],
@@ -1071,9 +1077,11 @@ module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, hi
]);
us = [
for (i=[0:higsteps1/10:higsteps1]) i,
0,
for (i=[higsteps1/10:higsteps1/10:higsteps1]) i,
for (i=[higsteps1+1:1:steps-higsteps2-1]) i,
for (i=[steps-higsteps2:higsteps2/10:steps]) i,
for (i=[steps-higsteps2:higsteps2/10:steps-higsteps2/10]) i,
steps
];
zang = atan2(r2-r1,h);
points = [
@@ -1086,7 +1094,8 @@ module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, hi
affine3d_translate([r, 0, h * (u-0.5)]) *
affine3d_xrot(90) *
affine3d_skew_xz(xa=zang) *
affine3d_scale([hsc,lerp(hsc,1,0.25),1]),
//affine3d_scale([hsc,lerp(hsc,1,0.25),1]),
scale([hsc,lerp(hsc,1,0.25),1], cp=[internal ? xmax : xmin, yctr, 0]),
pts = apply(mat, poly)
) pts
];