GCODE G02/G03 CNC Code (Circular Interpolation)

What is G02 g-code?

G02 instructs the CNC machine to move along a Circular Arc from its current position to a new coordinate. The movement is performed with a controlled federate. The new coordinate can be absolute or relative, depending on the effective mode (G90 or G91). This type of movement is called Circular interpolation.

What is the difference between G CODE G02 and G03?

With both commands, the machine will move from its current position to the same target coordinate. In G02, the movement will be clockwise (CW), and in G03, counter-clockwise (CCW).

G02/G03 Syntax

G02 and G03 can be written in two versions

Version 1 – “R” Syntax:

G02/G03 X12.5 Y14.7 R2.0 F0.2;
  • X, Y – The target coordinates at the end of the movement.
  • R – The arc’s radius.
  • F – The feedrate (Speed) at which the machine will move from the current position to the target position.

Version 2 – “IJK” Syntax?

G02/G03 X12.5 Y14.7 I1.0 J2.0 F0.2;
  • X, Y – The target coordinates at the end of the movement.
  • I, J – The arc’s center point coordinates relative to the starting coordinates.
  • F – The feedrate (Speed) at which the machine will move from the current position to the target position.
  • The radius will be calculated.

On a lathe machine, it will typically be the XZ plane (I,K with the IJK syntax). On a milling machine, it can be XY, YZ, or XZ, depending on the selected working plane (G17, G18, or G19).

  • G17 (XY Plane) – Use X, Y, I, and J.
  • G18 (XZ Plane) – Use X, Z, I, and K.
  • G19 (YZ Plane) – Use Y, Z, J, and K.

Read below for more details on the advantages and disadvantages of each syntax.

What does G02 Gcode do?

Gcode G02 G03 Sketch 1

The machine will move from its current position to the target position at a controlled federate. The endpoint position is calculated depending on the “mode” of the program. Absolute or Relative coordinate mode (GCODE G90 or G91) – The default depends on your controller. The actual path will be determined by the direction (G02 or G03) and the syntax format (IJK or R).

Use Examples of G02

Example #1CW movement along the Blue Arc in Absolute Mode – “R” Syntax.

N10 G90 (Setting Absolute mode);
N20 G01 X4.0 Y0.0 F0.1 ;
N30 Y2.0 (Position the machine at [P2]);
N40 G02 X10. Y10 R5.0 F0.5; (CW cirullar move to [P3] at a federate of 0.5);

Example #2CCW movement along the Orange Arc in Absolute Mode – “IJK” Syntax.

N10 G90 (Setting Absolute mode);
N20 G01 X4.0 Y0.0 F0.1 ;
N30 Y2.0 (Position the machine at [P2]);
N40 G03 X10. I3.0 J4.0 F0.5; (CCW cirullar move to [P3] at a federate of 0.5);

Example #3CW movement along the Blue Arc in Incremental Mode – “R” Syntax.

N10 G91 (Setting Incremental mode);
N20 G01 X4.0 F0.1 ;
N30 Y2.0 (Position the machine at [P2]);
N40 G02 X6. Y7. R5.0 F0.5; (CW cirullar move to [P3] at a federate of 0.5);

Example #4 – Full 360° circle. A full circle can be programmed only in “IJK” Syntax!

N10 G90 (Setting Absolute mode);
N20 G01 X4.0 Y0.0 F0.1 ;
N30 Y2.0 (Position the machine at [P2]);
N40 G02 I3.0 J4.0 F0.5(CW Full Circle starts and end on [P2]);

R Format Vs. IJK Format

G2 G3 360 Circle

The “R” format is simpler to write and also easier to understand. However, you should consider its limitations.

  • When the angle of the arc is greater than 180°, there are two potential solutions. As a result, the controller may not execute the exact movement you desire.
  • The start and end positions are identical when making a full 360° interpolation. In this case, there are an infinite number of solutions. 

Our recommendation is that the IJK format should always be used as it is fully defined, eliminating any confusion or errors!

R / IJ Conversion Calculator & Formulas

(*) The default values in the calculator correspond to the drawing example above.

R to IJ Conversion

Formulas:

Calculate the midpoint of the line connecting the start point (X1, Y1) and the endpoint (X2, Y2):

\( M_x = \frac{{X1 + X2}}{2} \)

\( M_y = \frac{{Y1 + Y2}}{2} \)

Calculate the distance d between the start point and the endpoint:

\( d = \sqrt{{(X2 – X1)^2 + (Y2 – Y1)^2}} \)

Calculate the height h from the midpoint to the center of the circle:

\( h = \sqrt{{R^2 – (\frac{d}{2})^2}} \)

Calculate the center of the circle (I, J):

If the arc is moving in the clockwise direction (G02), then

\( I = M_x + h \cdot \frac{{Y1 – Y2}}{d} \)

\( J = M_y + h \cdot \frac{{X2 – X1}}{d} \)

If the arc is moving in the counter-clockwise direction (G03), then

\( I = M_x – h \cdot \frac{{Y1 – Y2}}{d} \)

\( J = M_y – h \cdot \frac{{X2 – X1}}{d} \)

Finally, Convert I, J to be relative to the start point:

I = I – Y1
J= J−Y1

* Please note that these formulas assume that the arc does not exceed 180 degrees. For arcs that exceed 180 degrees, the situation is more complex because there are two possible!

IJ to R Conversion

Formulas:

Calculate the center of the circle (I, J):

I = I + X1
J = J + Y1
* where (X1, Y1) is the start point of the arc.

Calculate the radius R:

\( R = \sqrt{{(I – X1)^2 + (J – Y1)^2}}\)

Scroll to Top