Improvements to _gear_tooth_profile()

This commit is contained in:
Revar Desmera 2023-07-31 01:40:49 -07:00
parent 9f4b32c7f9
commit 1ae1c3cf0f

View file

@ -2280,19 +2280,22 @@ function _gear_tooth_profile(
brad = _base_radius(circ_pitch, teeth, pressure_angle, helical=helical), brad = _base_radius(circ_pitch, teeth, pressure_angle, helical=helical),
rrad = _root_radius(circ_pitch, teeth, clearance, helical=helical, profile_shift=profile_shift, internal=internal), rrad = _root_radius(circ_pitch, teeth, clearance, helical=helical, profile_shift=profile_shift, internal=internal),
adendum = _adendum(circ_pitch=circ_pitch, profile_shift=profile_shift),
dedendum = _dedendum(circ_pitch=circ_pitch, clearance=clearance, profile_shift=profile_shift),
clear = abs(dedendum-adendum),
srad = max(rrad,brad), srad = max(rrad,brad),
clear = default(clearance, circ_pitch/PI * 0.25),
tthick = circ_pitch/PI / cos(helical) * (PI/2 + 2*profile_shift * tan(pressure_angle)) - backlash, tthick = circ_pitch/PI / cos(helical) * (PI/2 + 2*profile_shift * tan(pressure_angle)) - backlash,
tang = tthick / prad / 2 * 180 / PI, tang = tthick / prad / 2 * 180 / PI,
// Generate a lookup table for the involute curve angles, by radius // Generate a lookup table for the involute curve angles, by radius
involute_lup = [ involute_lup = [
if (rrad < brad) if (clear > 0 && false)
each xy_to_polar(arc(n=4, r=min(brad-rrad,clear), corner=[ each xy_to_polar(
polar_to_xy(rrad,90+180/teeth), arc(n=16, r=clear, corner=[
polar_to_xy(rrad,90), [-0.1,rrad], [0,rrad], [0,rrad+clear]
polar_to_xy(brad,90), ])
])), ),
for (i=[0:5:arad/PI/brad*360]) for (i=[0:5:arad/PI/brad*360])
let( let(
xy = _involute(brad,i), xy = _involute(brad,i),
@ -2335,10 +2338,7 @@ function _gear_tooth_profile(
undercut_lup = [for (i=idx(undercut)) if (i>=uc_min) undercut[i]], undercut_lup = [for (i=idx(undercut)) if (i>=uc_min) undercut[i]],
// The u values to use when generating the tooth. // The u values to use when generating the tooth.
us = [ us = [for (i=[0:1:steps*2]) i/steps/2],
for (i=[0.0:0.02:0.2-EPSILON]) i,
for (i=[0:1:steps-1]) 0.2 + i/(steps-1)*0.8,
],
// Find top of undercut. // Find top of undercut.
undercut_max = max([ undercut_max = max([
@ -2354,15 +2354,41 @@ function _gear_tooth_profile(
// Generate the left half of the tooth. // Generate the left half of the tooth.
tooth_half_raw = deduplicate([ tooth_half_raw = deduplicate([
for (u = us) let( for (u = us)
r = lerp(rrad, ma_rad, u), let(
a1 = lookup(r, involute_lup) + soff, r = lerp(rrad, ma_rad, u),
a2 = lookup(r, undercut_lup), a1 = lookup(r, involute_lup) + soff,
a = internal || r < undercut_lup[0].x? a1 : min(a1,a2) a2 = lookup(r, undercut_lup),
) if(a<90+180/teeth) polar_to_xy(r, a), a = internal || r < undercut_lup[0].x? a1 : min(a1,a2)
for (i=[0:1:cap_steps-1]) let( )
a = ma_ang + soff - i * (cap_step-1) if( internal || r > (rrad+clear) )
) polar_to_xy(ma_rad, a), if(!internal || r < (ma_rad-clear) )
if(a<90+180/teeth)
polar_to_xy(r, a),
if (!internal)
for (i=[0:1:cap_steps-1]) let(
a = ma_ang + soff - i * (cap_step-1)
) polar_to_xy(ma_rad, a),
]),
// Round out the clearance valley
rcircum = 2 * PI * (internal? ma_rad : rrad),
rpart = (180/teeth-tang)/360,
round_r = min(clear, rcircum*rpart),
line1 = internal
? select(tooth_half_raw,-2,-1)
: select(tooth_half_raw,0,1),
line2 = internal
? [[0,ma_rad],[-1,ma_rad]]
: zrot(180/teeth, p=[[0,rrad],[1,rrad]]),
isect_pt = line_intersection(line1,line2),
rcorner = internal
? [last(line1), isect_pt, line2[0]]
: [line2[0], isect_pt, line1[0]],
rounded_tooth_half = deduplicate([
if (!internal) each arc(n=8, r=round_r, corner=rcorner),
each tooth_half_raw,
if (internal) each arc(n=8, r=round_r, corner=rcorner),
]), ]),
// Strip "jaggies" if found. // Strip "jaggies" if found.
@ -2381,14 +2407,20 @@ function _gear_tooth_profile(
mti = !angs? 0 : min_index(angs), mti = !angs? 0 : min_index(angs),
out = concat([path[i]], strip_left(path, i + mti + 1)) out = concat([path[i]], strip_left(path, i + mti + 1))
) out, ) out,
tooth_half = !undercut_max? tooth_half_raw : tooth_half = !undercut_max? rounded_tooth_half :
strip_left(tooth_half_raw, 0), strip_left(rounded_tooth_half, 0),
// Mirror the tooth to complete it. // Mirror the tooth to complete it.
tooth = deduplicate([ full_tooth = deduplicate([
each tooth_half, each tooth_half,
each reverse(xflip(tooth_half)), each reverse(xflip(tooth_half)),
]), ]),
// Reduce number of vertices.
tooth = path_merge_collinear(
resample_path(full_tooth, n=ceil(2*steps), closed=false),
),
out = center? fwd(prad, p=tooth) : tooth out = center? fwd(prad, p=tooth) : tooth
) out; ) out;