fix anchoring for $slop and small $fn

This commit is contained in:
Adrian Mariano 2022-10-14 18:54:57 -04:00
parent 1797d5dc91
commit 84daca0724

View file

@ -606,7 +606,9 @@ module screw(spec, head, drive, thread, drive_size,
named_anchor("threads_bot", [0,0,-length-shoulder_full+offset]), named_anchor("threads_bot", [0,0,-length-shoulder_full+offset]),
named_anchor("threads_center", [0,0,(-shank_len-length-_shoulder_len-shoulder_full-flat_height)/2+offset]) named_anchor("threads_center", [0,0,(-shank_len-length-_shoulder_len-shoulder_full-flat_height)/2+offset])
]; ];
vnf = head=="hex" && atype=="head" && counterbore==0 ? linear_sweep(hexagon(id=head_diam),height=head_height,center=true) : undef; rad_scale = _internal? (1/cos(180/sides)) : 1;
islop = _internal ? 4*get_slop() : 0;
vnf = head=="hex" && atype=="head" && counterbore==0 ? linear_sweep(hexagon(id=head_diam*rad_scale),height=head_height,center=true) : undef;
head_diam_full = head=="hex" ? 2*head_diam/sqrt(3) : head_diam; head_diam_full = head=="hex" ? 2*head_diam/sqrt(3) : head_diam;
attach_d = in_list(atype,["threads","shank","shaft"]) ? d_major attach_d = in_list(atype,["threads","shank","shaft"]) ? d_major
: atype=="screw" ? max(d_major,_shoulder_diam,default(head_diam_full,0)) : atype=="screw" ? max(d_major,_shoulder_diam,default(head_diam_full,0))
@ -622,7 +624,7 @@ module screw(spec, head, drive, thread, drive_size,
: head_height+flat_height+flat_cbore_height; : head_height+flat_height+flat_cbore_height;
attachable( attachable(
vnf = vnf, vnf = vnf,
d = attach_d, d = u_add(u_mul(attach_d, rad_scale), islop),
l = attach_l, l = attach_l,
orient = orient, orient = orient,
anchor = anchor, anchor = anchor,
@ -633,21 +635,21 @@ module screw(spec, head, drive, thread, drive_size,
difference(){ difference(){
union(){ union(){
screw_head(spec,details,counterbore=counterbore,flat_height=flat_height, screw_head(spec,details,counterbore=counterbore,flat_height=flat_height,
oversize=_internal?4*get_slop():0,teardrop=_teardrop); oversize=islop,teardrop=_teardrop);
if (_shoulder_len>0) if (_shoulder_len>0)
up(eps_shoulder-flat_height){ up(eps_shoulder-flat_height){
if (_teardrop) if (_teardrop)
teardrop(d=_shoulder_diam+(_internal?4*get_slop():0), h=_shoulder_len+eps_shoulder, anchor=FRONT, orient=BACK, $fn=sides); teardrop(d=_shoulder_diam*rad_scale+islop, h=_shoulder_len+eps_shoulder, anchor=FRONT, orient=BACK, $fn=sides);
else else
cyl(d=_shoulder_diam+(_internal?4*get_slop():0), h=_shoulder_len+eps_shoulder, anchor=TOP, $fn=sides, chamfer1=details ? _shoulder_diam/30:0); cyl(d=_shoulder_diam*rad_scale+islop, h=_shoulder_len+eps_shoulder, anchor=TOP, $fn=sides, chamfer1=details ? _shoulder_diam/30:0);
} }
if (shank_len>0 || pitch==0){ if (shank_len>0 || pitch==0){
L = pitch==0 ? length - (_shoulder_len==0?flat_height:0) : shank_len; L = pitch==0 ? length - (_shoulder_len==0?flat_height:0) : shank_len;
down(_shoulder_len+flat_height-eps_shank) down(_shoulder_len+flat_height-eps_shank)
if (_teardrop) if (_teardrop)
teardrop(d=d_major+(_internal?4*get_slop():0), h=L+eps_shank, anchor=FRONT, orient=BACK, $fn=sides); teardrop(d=d_major*rad_scale+islop, h=L+eps_shank, anchor=FRONT, orient=BACK, $fn=sides);
else else
cyl(d=d_major+(_internal?4*get_slop():0), h=L+eps_shank, anchor=TOP, $fn=sides); cyl(d=d_major*rad_scale+islop, h=L+eps_shank, anchor=TOP, $fn=sides);
} }
if (thread_len>0 && pitch>0) if (thread_len>0 && pitch>0)
down(_shoulder_len+flat_height+shank_len-eps_thread) down(_shoulder_len+flat_height+shank_len-eps_thread)
@ -2781,7 +2783,7 @@ function _validate_nut_spec(spec) =
function _validate_screw_spec(spec) = function _validate_screw_spec(spec) =
let( let(
dummy=echo_struct(spec,"Screw Specification"), //dummy=echo_struct(spec,"Screw Specification"),
systemOK = in_list(struct_val(spec,"system"), ["UTS","ISO"]), systemOK = in_list(struct_val(spec,"system"), ["UTS","ISO"]),
diamOK = _is_positive(struct_val(spec, "diameter")), diamOK = _is_positive(struct_val(spec, "diameter")),
pitch = struct_val(spec,"pitch"), pitch = struct_val(spec,"pitch"),