3dSynth

Tutorials / Custom G-code

Open in the interactive tutorials reader

---
title: Tutorial 14 Circles Without G2/G3
description: Drawing curves using only straight lines (Segmentation).
---

Tutorial 14 Circles Without G2/G3

1. Lesson Header

2. Concept Introduction

The Slicer Secret.
Most slicers don't output "circle commands". They output thousands of tiny straight lines (G1) that look like a circle.
This is called Linear Approximation or Discretization.

3. Machine State Explanation

Resolution.
- Hexagon: 6 sides. Looks blocky.
- Dodecagon: 12 sides. Looks smoother.
- 100-gon: Looks like a circle to the naked eye.
- Trade-off: More segments = smoother look = larger G-code file = more processing power needed.

4. Command Breakdown

Review of Trig:
- X = CenterX + Radius * cos(angle)
- Y = CenterY + Radius * sin(angle)

We will use this to calculate points.

5. Minimal Working Example

A Hexagon (6 sides).
Angle step = 360 / 6 = 60 degrees.
Radius = 10. Center = 50,50.

G1 X60 Y50
G1 X55 Y58.66
G1 X45 Y58.66
G1 X40 Y50
G1 X45 Y41.34
G1 X55 Y41.34
G1 X60 Y50

6. Visual Representation

The Polygon Limit:

Interactive preview is available in the interactive reader.

Start with a Triangle -> Square -> Pentagon -> ... -> Circle.
As N approaches infinity, the polygon approaches a circle.

7. Build Exercise

Task: Create a script (or manual G-code) for a 12-sided polygon (Dodecagon) with Radius 20mm.
Step = 30 degrees.

Solution:

; Center 100,100. Radius 20.
G1 X120 Y100
G1 X117.32 Y110
G1 X110 Y117.32
G1 X100 Y120
...

8. Deep Insight Section

STL Files are Polygons.
STL (Standard Tessellation Language) is made of triangles. It has no concept of "curves".
So when you export a cylinder from CAD to STL, it is already faceted. The slicer then slices those facets into G-code lines.
The printer is just executing a very high-resolution connect-the-dots game.

9. Common Failure Modes

  1. Stuttering: If you use 1000 segments for a small 5mm circle, the segments are 0.015mm long. The USB/Serial connection might not send commands fast enough, causing the printer to pause and blob.
  2. Overshoot: At high speeds, the printer might round off the corners of your polygon, accidentally making it smoother (but smaller) than intended.

10. Real-World Application

Low-Poly Art.
Designers intentionally use low segment counts (e.g., 6-sided cylinders) for aesthetic effect. You can control this directly in G-code.

11. Final Clean Version

Save this as lesson14.gcode.

; Lesson 14 - The Faceted Circle
G28
G1 Z0.3
G1 F3000

; --- Hexagon (R=20) ---
G1 X120 Y100 ; Start
G1 X110 Y117.32
G1 X90 Y117.32
G1 X80 Y100
G1 X90 Y82.68
G1 X110 Y82.68
G1 X120 Y100 ; Close

; --- Square (R=20) ---
G1 X120 Y100
G1 X100 Y120
G1 X80 Y100
G1 X100 Y80
G1 X120 Y100

; Finish
G28 X0 Y0

12. Stretch Challenge

Challenge: Write a Python or JavaScript snippet to generate the G-code for an N-sided polygon.

Answer Key:

function generatePolygon(n, radius, cx, cy) {
  let gcode = "";
  for (let i = 0; i <= n; i++) {
    let angle = (i * 2 * Math.PI) / n;
    let x = cx + radius * Math.cos(angle);
    let y = cy + radius * Math.sin(angle);
    gcode += `G1 X${x.toFixed(3)} Y${y.toFixed(3)}\n`;
  }
  return gcode;
}