In CNC machining, at least the kind I do on my Sherline CNC mill, you can’t mill around acute inside corners: a round milling bit doesn’t fit into a straight-sided angle. You must add a fairing arc that smoothly connects the two sides; the catch is that “smooth” means it’s tangent to the sides. And EMC2 is really, really fussy about smooth, to the point where you can’t just wing it with a calculator and type in the numbers.
There are nice analytic geometry methods for finding the intersection of two line segments, then laying in the arc that connects them, but this example weighs in at over two pages of G-Code. Mostly, what I need is an arc that connects a vertical or horizontal edge to an angled edge, so some simplification is in order.
Herewith, the quick-and-dirty…
The cutter enters from the left side, moving horizontally to the right, and will depart along the line toward P1, which might be the next corner of the part. The two material edges meet at P0, the vertex of the angle. The fairing arc is tangent to the two edges at PA and PB, centered at PC, and with a radius R.
We know the coordinates of P0 and P1 and the arc radius. That radius must be larger than the cutter radius, as you can’t tuck a fat cutter into a narrow corner.
The problem is to find PA, PB, and PC, so that we can write the G-code commands that travel along the sides & the arc.
The first step is finding Φ (Phi), the angle between the outgoing edge and the X axis:
Φ = arctan Δy/Δx = arctan (P1y – P0y) / (P1x – P0x)
I’m pretty sure if you use a 4-quadrant arctan, as shown in the doodle, all the angles will work out perfectly on either side of the axis, but it’s easy enough to fake the signs to get the right answer in any specific case. If you wanted a general solution, you’d have a two-page subroutine, right?
You’ll need the complement of that angle, hereinafter known as Theta:
Θ = 90 – Φ
Find the distances between various points using good old trig and right triangles:
- CBx = R · sin Φ
- CBy = R · cos Φ
- P0PBy = R · (1 – cos Φ)
- P0PBx = P0PBy · tan Θ
Then the coordinates fall out thusly:
- PCy = P0y + R
- PBy = PCy – CBy
- PBx = P0x + P0PBx
- PCx = PBx – CBx
- PAx = PCx
- PAy = P0y
Remember, you do not figure all this out with your calculator and plug the numbers into the G-code, not if you have any sense. If you have just a few corners, write the commands directly, otherwise gimmick up a little subroutine. Earlier versions of EMC2 used numbered parameters (#100), but now that you can have named parameters (#<_Fairing_Radius>), what’s holding you back?
#<_CBy> = [#<_Fairing_Radius> * COS [#<_Phi>]] (Y distance PC to PB)
If your edge doesn’t come in from the left, then manual 90 degree rotations apply.
0: (x,y) -> (x,y) 90: (x,y) -> (y,-x) 180: (x,y) -> (-x,-y) 270: (x,y) -> (-y,x)
If you’re using a CAD program to lay out your parts, all this is largely irrelevant. I hammer out the G-code for the simple 2-1/2-D parts I make by hand, so rounding off a few corners comes in handy.
Because the lines & arc define the material edge contour, you can mill on either side of it and use cutter radius compensation to make the answer come out right. Works like a champ!
For what it’s worth, the arc is tangent at PA and PB, making the line from PC to the corner (a.k.a. vertex) P0 the bisector of angle Φ. That’s not directly useful here, but keep it in mind when you solve similar problems.
Update: As of mid-January, the newest trunk version of EMC2 can automagically insert fillets when cutter comp is turned on. That’ll be in the stable version in a while, after which I’ll need this math only for decorative fillets. That’s fine with me!