How can I write G-code for a triangle without sharp tips?
I want to generate the corners manually, rather than using a slicer to generate them, just to know how it is done.
3D Printing Stack Exchange is a question and answer site for 3D printing enthusiasts. It only takes a minute to sign up.Sign up to join this community
First, convert the given measurements into a sketch...
we actually have the printer do circles.. let's plot that out...
G92 X0 Y0 ; the current position is now (0,0) on the XY G90 ;Abolute mode for everything... M83 ;...but for the E-argument, so you can just put the length into the extrusions that are to be done G0 X10.66 Y2 G2 R5 X6.33 Y9.5 ; Alternate: G3 I0 J5 X6.33 Y9.5 G1 X45.66 Y77.638 G2 R5 X54.33 Y77.638 ; Alternate: G3 I4.33 Y-2.5 X54.33 Y77.638 G1 93.67 Y9.5 G2 R5 X89.33 Y2 ; Alternate: G3 I-4.33 Y-2.5 X89.33 Y2 G1 X10.66 Y2 G0 X0 Y0 G91 ; return to relative coordinates
This code has to be prefixed by a move to where you want to start the pattern and will not know if you move it off the build plate, so keep 100 mm X and 87 mm in Y of the allowable build plate. It will end exactly where you started it.
In many uses of g-code, rounded corners are actually n-gons with a very high number n. then we only need
G1 and can easily calculate the length of the stretches and fill in the G1. We need to iterate down to somewhat circular...
Let's start iterating with n=3 aka a triangle, which gives a direct line over the corner gives this:
going to n=6 (hexagon) follows the curve a lot better...
going to n=12 looks almost round on a larger scale...
and when we reach n=24, we are pretty close to the circle..
And as we go above n=6, we also get easier math for the corners, as we always get the same lengths of movement along X and Y just swapped around due to symmetry.
With all these stretches defined, we could start to work in relative coordinates easily, again without E, and only for the bottom left corner:
G0 X10.66 Y2 G1 X-1.294 Y0.17 G1 X-1.206 Y0.5 G1 X-1.036 Y0.795 G1 X-0.795 X1.036 G1 X-0.5 Y1.206 G1 X-0.17 Y1.294 G1 X0.17 Y1.294 G1 X0.5 Y1.036 ...
G2 (clockwise arc) and
G3 (counterclockwise arc) commands that could be used to do this. You can find detailed documentation for the command here.
Basically, you can use
G2 R1 X5 Y5
to draw a (clockwise) arc from the current position to $(X,Y)=(5,5)$ with a radius of $1$.
So, your rounded triangle could be drawn with 3 straight line moves and 3 arc moves. Figuring out the exact coordinates for each move would be a quite challenging geometry exercise, as you'd need to know where the straight line portion of each side ends and the rounded portion starts.