I encountered the following question in a manufacturing course.

G20 G90 G28

M06 T1

MO3 S1000

G00 X0 Y0 Z-0.25

G41 D1

G01 X1 Y1 Z-0.25 F3

G01 X5 Y1 Z-0.25 F3

G01 X5 Y3 Z-0.25 F3

G01 X1 Y1 Z-0.25 F3

G00 X4 Y0 Z0.25


But when you type the G code in NCViewer the shape produced is not a rectangle. Also, I am not sure how the end mill diameter affects that of the rectangle. Can anyone explain how to solve this problem?

• people make mistakes. there may be a line missing. care to guess what that line would be?
– Abel
Nov 27, 2021 at 22:31
• Glad to see my site helping others learn about gcode still! :) Just wanted to help a bit by explaining that in most cases, gcode positions describe the position of the CENTER of the tool, and therefore half the endmill will stick out on each side of the position. For a rectangle you add or subtract the 2*ToolRadius (once on each side) for the final size. A pocket in material is larger(add), a contour outside the material is smaller(subtract). Good luck! Nov 27, 2021 at 23:26
• Also just to note I think this question implies the tool is outside the material as phrased, but I could see someone interpreting this as inside material (e.g. cutting a window in sheet metal) so it's a shame the question didn't clarify the type of cut. Nov 27, 2021 at 23:28

There is no rectangle, the assignment is wrong. In order to make a rectangle, the G-code should have been:

...
G01 X1 Y1 Z-0.25 F3
G01 X5 Y1 Z-0.25 F3
G01 X5 Y3 Z-0.25 F3
G01 X1 Y3 Z-0.25 F3 ; <-- missing line
G01 X1 Y1 Z-0.25 F3
...


Then the rectangle would have been 2 by 4 inches.

As noted in the comments, the assignment is even more unclear. The code shows an offset to be taken into account of tool D1 in the cutter compensation code G41. It further doesn't specify the characteristics of that tool. If it is differently than the end mill currently in the tool head, than the difference in diameter between the D1 tool and the current 0.5" tool needs to be taken into account. The power of using cutter offset definitions is that the same code can be used for different tools, you only needs to set the correct offset. If the D1 tool is defined as a 1" diameter tool, the current tool is half that size, as there is a compensation for 1" at play while a half inch end mill is used, the end product will be larger.

• There are also further omissions in the assignment. The G41 D1 command sets radius compensation for tool number 1, but we do not know what radius the tool table has for that tool. From the initial X0 Y0 Z-0.25 it appears we are conventional cutting on the outside, but in that case G41 applies the compensation in wrong direction and G42 would be more appropriate.
– jpa
Nov 28, 2021 at 8:59