<p>There is no rectangle, the assignment is wrong. In order to make a rectangle, the G-code should have been:</p>
<pre><code>...
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 ; &lt;-- missing line
G01 X1 Y1 Z-0.25 F3
...
</code></pre>
<p>Then the rectangle would have been 2 by 4 inches.</p>
<hr />
<p>As noted in the comments, the assignment is even more unclear. The code shows an offset to be taken into account of tool <code>D1</code> in the cutter compensation code <code>G41</code>. 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 <code>D1</code> tool and the current 0.5&quot; 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 <code>D1</code> tool is defined as a 1&quot; diameter tool, the current tool is half that size, as there is a compensation for 1&quot; at play while a half inch end mill is used, the end product will be larger.</p>

CC BY-SA 4.0
2021-11-28T08:59:08.430Z
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
CC BY-SA 4.0
2021-11-27T22:36:16.237Z
2021-11-28T15:58:21.717Z
2021-11-28T15:58:21.717Z
0scar
<p>I encountered the following question in a manufacturing course.</p>
<p><a href="https://i.sstatic.net/ZZL4W.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZZL4W.png" alt="enter image description here" /></a></p>
<pre><code>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 
</code></pre>
<p>But when you type the G code in <a href="https://ncviewer.com/" rel="nofollow noreferrer">NCViewer</a> 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?
<a href="https://i.sstatic.net/M59Ir.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/M59Ir.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-11-27T22:31:38.990Z
people make mistakes.  there may be a line missing.  care to guess what that line would be?
Abel
CC BY-SA 4.0
2021-11-27T23:26:28.587Z
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!
Xander Luciano
CC BY-SA 4.0
2021-11-27T23:28:39.377Z
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.
Xander Luciano
<g-code><cnc>
Interpreting G-code to answer question about geometry of shape produced
user389532
# Interpreting G-code to answer question about geometry of shape produced

(Asked by: username_0 on 2021-11-27)

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?

**Tags:** g-code, cnc
> **Comments:**
> **username_1**: people make mistakes.  there may be a line missing.  care to guess what that line would be?  
> **username_2**: 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!  
> **username_2**: 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.  

---

## 1 answers

### Answer by username_3 on 2021-11-27. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_4**: 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.  

---

