G-Code Mirror

Invert toolpaths across an axis. This tool automatically inverts coordinates, updates I/J/K arc vectors, and smartly swaps G02/G03 directions and G41/G42 cutter compensation to maintain correct geometry.

Mirror Options
Inverts X and I values
Inverts Y and J values
Inverts Z and K values
Comments (e.g. (X0.0 Y0.0)) are automatically ignored.
Original G-Code
Click or drag G-code file here Supports .nc, .txt, .gcode
Mirrored Result

How the G-Code Mirror Works

The mirror reverses the sign of every coordinate on the axes you choose, so the toolpath is reflected about program zero. Where a reflection needs it, it also swaps the arc direction and cutter compensation codes, so the mirrored program still cuts a proper part.

Mirroring is the quick way to make the opposite-hand version of a part, such as a left and right bracket or a pair of handed mounting plates, without going back to CAM. The reflection line is always zero on the axis you mirror. Mirroring X reflects the path about X0 of the active work offset, so a point programmed at X2.0 ends up at X-2.0. Make sure your part zero sits on the line you want to reflect about, or move the result afterwards.

The page works on the text of the program one line at a time. It does not simulate the program or track modal states, so it cannot tell a coordinate from a dwell time or an offset value. Read the limits below before you run anything it produces.

How It Works

Coordinates
Mirror X: X → −X, I → −I
Mirror Y: Y → −Y, J → −J
Mirror Z: Z → −Z, K → −K
A changed number keeps its original number of decimal places, limited to between 3 and 5. A number written without a decimal point comes back with 4. Everything from an opening bracket (or from a semicolon, on a line with no bracket) to the end of the line is treated as a comment and left untouched, so keep comments at the ends of lines.
Arcs and Compensation
X only or Y only: G02 ↔ G03, G41 ↔ G42
X and Y together: no swap
Z: no effect on arc direction
A reflection in one axis reverses the direction of travel round every arc, so clockwise becomes anticlockwise. Mirroring both X and Y is the same as turning the part through 180°, which keeps arcs and compensation as they were. The rule is correct for arcs in the XY plane (G17). R-word arcs keep their radius.

Worked Examples

Input: profile with a G41 lead-in
Original
G90 G17 G54
G0 X1.0 Y0.5
G41 D1 G1 X2.0 Y0.5 F20.
G3 X2.5 Y1.0 I0 J0.5
G1 X2.5 Y2.0 (TOP X2.5)
G40 G1 X3. Y2.25
Output: Mirror X only
Mirrored result
G90 G17 G54
G0 X-1.000 Y0.5
G42 D1 G1 X-2.000 Y0.5 F20.
G02 X-2.500 Y1.0 I0.0000 J0.5
G1 X-2.500 Y2.0 (TOP X2.5)
G40 G1 X-3.000 Y2.25
  • G41 became G42 and G3 became G02 (the page writes the two-digit form).
  • X1.0 became X-1.000 because 3 decimals is the minimum. I0 had no decimal point, so it is written I0.0000.
  • Y values and the comment (TOP X2.5) are unchanged.

Run the same program with both Mirror X and Mirror Y switched on and every X, Y, I and J value changes sign, but G41 and G3 stay as they are, because the result is a 180° rotation rather than a reflection.

Tips for Using the Results

  • Expect climb milling to become conventional. A single-axis mirror makes the tool travel the other way round the profile. Swapping G41 and G42 keeps the cutter on the correct side of the line, but a climb-milled profile is now cut conventionally. Expect a different finish and tool load, or reverse the path in CAM if you need climb milling.
  • Mirror about another line. The page always reflects about zero. To reflect about X50, mirror X and then add 100 (twice the line position) with the G-Code XYZ Shifter.
  • Check lines that are not moves. Every X, Y, Z, I, J and K value is negated whatever it means. A dwell such as G04 X1.5 becomes G04 X-1.500, and values on G10, G52, G92, G28 or G53 lines change sign too. Drilling-cycle R and Q values are not touched, so mirroring Z leaves the R plane where it was. Edit these lines by hand.
  • Do not mirror thread milling paths. Reversing the arc direction of a helical path changes the hand of the thread, so a right-hand thread comes out left-hand. Regenerate it with the Thread Milling Generator instead.
  • Backplot before cutting. Load the result into the G-Code 3D Viewer, then prove it out on the machine with single block and reduced rapids.

Frequently Asked Questions

A reflection reverses the direction of travel. An arc cut clockwise in the original is cut anticlockwise in the mirror image, so G02 (clockwise) has to become G03 (anticlockwise) to follow the same curve. If the code were left alone, the arc would bulge the wrong way or the control would alarm because the end point and centre no longer match.

G41 offsets the cutter to the left of the direction of travel and G42 to the right. After a single-axis mirror, what was the left side of the path is now the right side, so the codes swap to keep the cutter outside a profile and inside a pocket. The offset number (D) is not changed.

No. Mirroring both X and Y is the same as rotating the part 180° about zero, which does not change clockwise or anticlockwise travel. The page only swaps G02/G03 and G41/G42 when exactly one of X and Y is mirrored. Mirroring Z on its own never swaps them.

Mirror the program, then use the G-Code XYZ Shifter to add twice the centreline position on that axis. For example, to reflect about X50, mirror X and then shift X by +100. Alternatively, put the work zero on the centreline before you post the program.

Many controls can mirror at run time without editing the file, for example with G51.1 on many Fanuc-style controls or with mirror image settings on others. Check your control manual for how it handles arcs and cutter compensation. A run-time mirror keeps one proven program for both hands.

Mirrored programs must be checked before cutting. Backplot the result, check cutter compensation, the cutting direction and any dwell or offset lines, and prove the program out with single block and reduced rapids.