Merge pull request #1258 from BelfrySCAD/revarbat_dev

Fix for cyl() teardrop rounding.
This commit is contained in:
Revar Desmera 2023-08-19 00:42:16 -07:00 committed by GitHub
commit 6a42df748b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1590,7 +1590,7 @@ function cyl(
[r1, -l/2] + polar_to_xy(chamf1l,90+vang), [r1, -l/2] + polar_to_xy(chamf1l,90+vang),
] ]
else if (!approx(round1,0) && td_ang < 90) else if (!approx(round1,0) && td_ang < 90)
each _teardrop_corner(r=abs(round1), corner=[[max(0,r1-2*roundlen1),-l/2],[r1,-l/2],[r2,l/2]], ang=td_ang) each _teardrop_corner(r=round1, corner=[[max(0,r1-2*roundlen1),-l/2],[r1,-l/2],[r2,l/2]], ang=td_ang)
else if (!approx(round1,0) && td_ang >= 90) else if (!approx(round1,0) && td_ang >= 90)
each arc(r=abs(round1), corner=[[max(0,r1-2*roundlen1),-l/2],[r1,-l/2],[r2,l/2]]) each arc(r=abs(round1), corner=[[max(0,r1-2*roundlen1),-l/2],[r1,-l/2],[r2,l/2]])
else [r1,-l/2], else [r1,-l/2],
@ -1623,16 +1623,18 @@ function cyl(
function _teardrop_corner(r, corner, ang=45) = function _teardrop_corner(r, corner, ang=45) =
let( let(
check = assert(len(corner)==3) assert(is_finite(r)) assert(is_finite(ang)), check = assert(len(corner)==3)
cp = circle_2tangents(r, corner)[0], assert(is_finite(r))
path1 = arc(r=r, corner=corner), assert(is_finite(ang)),
cp = circle_2tangents(abs(r), corner)[0],
path1 = arc(r=abs(r), corner=corner),
path2 = [ path2 = [
for (p = select(path1,0,-2)) for (p = select(path1,0,-2))
if (v_theta(p-cp) >= -ang) p, if (abs(modang(v_theta(p-cp)-90)) <= 180-ang) p,
last(path1) last(path1)
], ],
path = [ path = [
line_intersection([corner[0],corner[1]],[path2[0],path2[0]+polar_to_xy(1,-90-ang)]), line_intersection([corner[0],corner[1]],[path2[0],path2[0]+polar_to_xy(1,-90-ang*sign(r))]),
each path2 each path2
] ]
) path; ) path;