CNC
G-code arc calculator
Arc centers I, J, K for G02 and G03 from a radius, and back again.
Arc centre
I1. J0.
- R
- R1.
- Sweep
- 90°
- Arc length
- 1.5708 in
- R-1. instead
- I0. J1., 270°
G02 X1. Y1. I1. J0.G02 X1. Y1. R1.Why: I1 J0 puts the centre at X1 Y0: 90° of arc, 1.5708 long.
Why these numbers?
The situation
G02 from X0 Y0 to X1 Y1 with R1.
From your input: the start, end and arc
What that means
Two points and a radius fit two circles. Their centres sit on the chord’s perpendicular, √(R² − (chord/2)²) = .7071 either side of its midpoint.
Geometry: exact by definition
So
A positive R takes the short way round, 180° or less; a negative R the long way, past 180°.
Two sources: Haas Automation and LinuxCNC , sources [1, 2]
So
I, J and K are measured from the arc’s start point to its centre, not from the part zero (unless the control is in an absolute arc-centre mode such as LinuxCNC’s G90.1).
Two sources: Haas Automation and LinuxCNC , sources [1, 2]
The number
I1 J0: 90° of arc, 1.5708 long (length = R × sweep in radians).
Geometry: exact by definition
Sources
What next
How the g-code arc calculator works
A G02 from X0 Y0 to X1 Y1 with R1 has its center at I1.0000 J0.0000, sweeping 90° along 1.5708 in of arc.
How to calculate I and J
Maintained by John, former CNC lathe programmer
What it does
A G02 (clockwise) or G03 (counterclockwise) arc runs from where the tool is to the end point. The control needs the centre: either as I, J and K, the distance from the start point to the centre, or as R, the radius, and it works the centre out. This calculator goes both ways and checks that the end point is really on the circle.
Formulas
I and J
I = centre X − start X J = centre Y − start Y
- I, J, K
- incremental, start point to centre, in the active plane (G17 I/J, G18 I/K, G19 J/K)
Centre from R
h = √(R² − (c ÷ 2)²)
- c
- the chord, start to end
- h
- how far the centre sits off the chord’s midpoint, square to it
Arc length
L = R × sweep (radians) = R × sweep° × π ÷ 180
Worked example
A G02 in G17 from X0 Y.5 to X.5 Y0 with R.5:
- Chord = √(.5² + .5²) = .7071; the centre sits √(.5² − .3536²) = .3536 off its midpoint (.25, .25)
- Clockwise with R+ takes the right of the chord: the centre is X0. Y0.
- I = 0. − 0 = 0., J = 0. − .5 = -.5
- G02 X.5 Y0 I0. J-.5: 90° of arc, .7854 long
With R−.5 the same points give the other circle: I.5 J0., 270° the long way round, 2.3562 long. And R.2 can't reach: R.2 is too small to reach the end point: it needs at least .3536.
Gotchas
- I and J are from the start, not from zero
- On Haas, Fanuc-style and LinuxCNC controls in their default mode, I and J run from where the tool is to the centre. Using the centre’s absolute coordinates puts the arc somewhere else entirely.
- The sign of R
- Two circles of radius R pass through any two points. R+ picks the arc of 180° or less, R− the longer one. A sign slip cuts the wrong side of the part.
- Full circles
- When the start and end are the same point, every circle through it fits, so R can’t say which: a full circle needs I/J.
- Arcs near 180°
- Close to a half circle the centre moves a long way for a tiny change in R or the end point. I/J pins the centre exactly; prefer it there.
- End point off the circle
- With I/J, the end must be the same distance from the centre as the start. Rounding in a hand-made program puts it off by a few tenths and the control alarms; the calculator gives the corrected end.
- Lathe X is a diameter
- On a lathe X is programmed as a diameter but I is a radius. The calculator halves X for the geometry and gives I as a radius.
Sources
The centre, sweep and length are circle geometry, cited rather than counted. What I, J, K and the sign of R mean are the control makers’ own rules; two agree:
- Haas Automation — Mill G02 CW / G03 CCW circular interpolation motion
- LinuxCNC — G-code reference: G2, G3 arc move and G90.1, G91.1 arc distance mode
More on the codes: G02 and G03. Check a whole program, arcs included, in the G-code checker.