---
title: Tutorial 5 Closing Shapes Correctly
description: Why absolute coordinates are better than relative for geometry.
---
Tutorial 5 Closing Shapes Correctly
1. Lesson Header
- Lesson Number: 5
- Level: Beginner
- Title: Closing Shapes Correctly
- Estimated Duration: 15 Minutes
- Prerequisites: Lesson 2 (Relative Motion)
- What You Will Build: A "perfect" square with no gaps.
2. Concept Introduction
The Problem: "Drift."
Imagine walking 10 steps forward, turning 90 degrees, walking 10 steps, turning... If you do this 4 times, do you end up exactly where you started? Probably not. Maybe you took a slightly larger step on the third leg.
In G-code, this is the difference between Absolute Positioning (G90) and Relative Positioning (G91).
- Relative (
G91): "Move X+10". If the motor skips a microstep or the math rounds9.999to10.0, errors accumulate. By the 100th move, you might be millimeters off. - Absolute (
G90): "Go to X10." Even if the previous move was wrong, this command forces the machine to a known grid location.
Rule: Always use Absolute Positioning for the main geometry of a print. Use Relative only for small, temporary shifts (like hopping over a part).
3. Machine State Explanation
The Coordinate System Grid
Your printer's bed is a piece of graph paper.
- (0,0) is usually Front-Left.
- (200,200) is usually Back-Right.
When you use G90, you are placing dots on specific grid intersections.
When you use G91, you are saying "Move 1 square right from wherever you happen to be."
4. Command Breakdown
Absolute Positioning (G90)
Sets the machine to interpret X/Y/Z/E values as coordinates on the bed.
- Syntax: G90
- Default: Most machines default to this.
Relative Positioning (G91)
Sets the machine to interpret values as "distance to move."
- Syntax: G91
- Danger: Easy to crash if you forget you are in this mode.
5. Minimal Working Example
Let's draw a square using both methods to see the difference mentally.
Bad Way (Relative - G91):
G91
G1 X10 ; Right
G1 Y10 ; Back
G1 X-10 ; Left
G1 Y-10 ; Front (Hopefully back to start)
Risk: If a step is lost, the square doesn't close.
Good Way (Absolute - G90):
G90
G1 X10 Y10 ; Start Point
G1 X20 Y10 ; Right
G1 X20 Y20 ; Back
G1 X10 Y20 ; Left
G1 X10 Y10 ; Close the loop (Back to Start)
Benefit: The final command explicitly sends the nozzle to 10,10. It must close the loop.
6. Visual Representation
Interactive preview is available in the interactive reader.
Notice how we define the corners, not the lengths of the sides.
7. Build Exercise
Task: Write a program to draw a triangle with vertices at:
1. (50, 50)
2. (100, 50)
3. (75, 100)
Use Absolute Positioning (G90).
...
Solution:
G21
G90 ; Absolute
G28 ; Home
G0 Z0.3
G0 X50 Y50 ; Vertex 1 (Start)
G1 X100 Y50 ; Vertex 2
G1 X75 Y100 ; Vertex 3
G1 X50 Y50 ; Back to Vertex 1 (Close Loop)
8. Deep Insight Section
Why Slicers Mix Both
If you open a G-code file from Cura or PrusaSlicer, you might see G90 at the top, but M83 (Relative Extrusion) for the E-axis.
- X/Y/Z: Absolute. We want the shape to be correct relative to the bed.
- E: Relative. We just want to push "some amount" of plastic. Calculating the total accumulated filament for a 10-hour print (e.g., "Extrude to 45321.4mm") is messy and prone to floating-point rounding errors.
So the standard modern header is:
G90 ; Absolute XYZ
M83 ; Relative E
9. Common Failure Modes
- The "Drifting Print": If you accidentally leave
G91on, the printer might try to move toX2000because it thinks you meant "Move 100mm more" ten times in a row. - Unclosed Loops: In Relative mode, if you calculate
X10thenX-9.9, you have a 0.1mm gap. In Absolute,X10andX10are the same point.
10. Real-World Application
CNC Machining vs. 3D Printing
In CNC milling, G91 (Incremental) is used often for subroutines—e.g., "Drill a hole here, then move 10mm right and repeat the exact same drilling code."
In 3D Printing, since the geometry is unique for every layer, we almost exclusively use G90.
11. Final Clean Version
Save this as lesson5.gcode.
; Lesson 5 - The Perfect Triangle
; Setup
G21 ; Millimeters
G90 ; Absolute Positioning
M83 ; Relative Extrusion
G28 ; Home
; Move to Start
G0 Z0.3 ; First layer height
G0 X50 Y50 ; Vertex 1
; Draw Triangle
G1 F1500
G1 X100 Y50 E5 ; Base
G1 X75 Y90 E5 ; Right Side
G1 X50 Y50 E5 ; Left Side (Closes Loop)
; Finish
G0 Z10 ; Lift
G0 X0 Y200 ; Park
12. Stretch Challenge
Challenge: Draw a "Bowtie" shape using 5 points.
Center is at (100, 100).
Wings go out to X=80 and X=120.
Answer Key:
G0 X100 Y100 ; Center (Start)
G1 X80 Y120 ; Top Left
G1 X80 Y80 ; Bottom Left
G1 X100 Y100 ; Center
G1 X120 Y120 ; Top Right
G1 X120 Y80 ; Bottom Right
G1 X100 Y100 ; Center (Close)