keyhole 2D path
#1370
Replies: 3 comments
-
Here is another way which is cleaner I think:
Unfortunately the existing round_corners() didn't work, so I made a simple round_path() using offset(). |
Beta Was this translation helpful? Give feedback.
0 replies
-
I fleshed out a more complex version with error checking, which allows either circle to be the big one. function keyhole(l, r1, r2, shoulder_r) =
assert(is_num(l) && l>0)
assert(is_num(r1) && r1>0)
assert(is_num(r2) && r2>0)
assert(l>=max(r1,r2))
assert(is_undef(shoulder_r) || (is_num(shoulder_r) && shoulder_r>0))
let(
cp1 = [0,0],
cp2 = cp1 + [0,-l],
shoulder_r = is_num(shoulder_r)? shoulder_r : min(r1,r2) / 2,
minr = min(r1, r2) + shoulder_r,
maxr = max(r1, r2) + shoulder_r,
dy = opp_hyp_to_adj(minr, maxr),
spt1 = r1>r2? cp1+[minr,-dy] : cp2+[minr,dy],
spt2 = [-spt1.x, spt1.y],
ds = spt1 - (r1>r2? cp1 : cp2),
ang = atan2(abs(ds.y), abs(ds.x)),
path = r1>r2? [
each arc(r=shoulder_r, cp=spt1, start=180-ang, angle=ang, endpoint=false),
each arc(r=r2, cp=cp2, start=0, angle=-180, endpoint=false),
each arc(r=shoulder_r, cp=spt2, start=0, angle=ang, endpoint=false),
each arc(r=r1, cp=cp1, start=180+ang, angle=-180-2*ang, endpoint=false),
] : [
each arc(r=shoulder_r, cp=spt1, start=180, angle=ang, endpoint=false),
each arc(r=r2, cp=cp2, start=ang, angle=-180-2*ang, endpoint=false),
each arc(r=shoulder_r, cp=spt2, start=360-ang, angle=ang, endpoint=false),
each arc(r=r1, cp=cp1, start=180, angle=-180, endpoint=false),
]
) path; |
Beta Was this translation helpful? Give feedback.
0 replies
-
I've added |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted to make a keyhole shape, to make the kind of hole used to hang objects on the wall using a screw:
I wanted to specify the two radiuses, and be able to alter the distance between the two, and I wanted rounded corners. This was much more complicated than I thought, and this is the only way I came up with:
Can it be done in a simpler, more elegant way?
Beta Was this translation helpful? Give feedback.
All reactions