---
title: Tutorial 41 Adaptive Printing
description: Toolpaths that react to the environment.
---
Tutorial 41 Adaptive Printing
1. Lesson Header
- Lesson Number: 41
- Level: Master
- Title: Adaptive Printing
- Estimated Duration: 60 Minutes
- Prerequisites: Lesson 40 (Feedback), Lesson 32 (Non-planar)
- What You Will Build: An "Adaptive Layer Height" Slicer Logic.
2. Concept Introduction
Static vs Dynamic.
Standard G-code is static. Once sliced, it's fixed.
Adaptive Printing changes the plan based on geometry or conditions.
Most common: Adaptive Layer Height.
Slope is steep -> Thin layers (0.1mm) for detail.
Slope is vertical -> Thick layers (0.3mm) for speed.
3. Machine State Explanation
The Gradient.
Slope = dz/dx.
If slope is high (horizontal surface), we need thin layers to avoid "stair-stepping".
If slope is low (vertical wall), we can use thick layers.
4. Command Breakdown
- Math: Calculating the tangent of the surface.
- Variable Layer Height: Changing Z steps dynamically.
5. Minimal Working Example
The Sphere Strategy.
Top of sphere (flat): dz is small per dx. Need thin layers.
Equator of sphere (vertical): dz is large per dx. Can use thick layers.
6. Visual Representation
Interactive preview is available in the interactive reader.
7. Build Exercise
Task: Write a Python script to slice a Hemisphere (R=20) with adaptive layers.
Min Layer: 0.1mm.
Max Layer: 0.3mm.
Max Stepover (Horizontal offset per layer): 0.2mm.
Algorithm:
1. Start at Z=0.
2. Calculate radius r at current Z.
3. Calculate next candidate Z (Z + Max_Layer).
4. Check horizontal offset dr = r(Z) - r(Z_next).
5. If dr > Max_Stepover, reduce layer height until dr <= Max_Stepover.
6. Or hit Min_Layer.
7. Write G-code layer.
8. Deep Insight Section
Flow Compensation.
When layer height changes, flow must change!Volume = Width * Height * Length.
If height drops from 0.2 to 0.1, E must drop by 50% (assuming constant width).
Slicers handle this automatically, but manual scripts must be careful.
9. Common Failure Modes
- Flow Mismatch: Forgetting to scale E with Z-height.
- Cooling: Thin layers print faster. If too fast, the previous layer is still molten. You need to slow down
Ffor thin layers.
10. Real-World Application
Non-Planar Slicing (Again).
True adaptive printing changes not just height but orientation.
5-axis slicers rotate the part to keep the nozzle perpendicular to the surface.
This eliminates support material entirely.
11. Final Clean Version
The Adaptive Slicer:
import math
filename = "adaptive_sphere.gcode"
R = 20
min_h = 0.1
max_h = 0.3
max_stepover = 0.2 # Max horizontal error
with open(filename, "w") as f:
f.write("G28\nG1 Z0 F3000\n")
current_z = 0
while current_z < R:
# Determine next layer height
h = max_h
# Binary search or simple iterative check for best h
# Condition: r_current - r_next <= max_stepover
# r = sqrt(R^2 - z^2)
r_curr = math.sqrt(R**2 - current_z**2)
while h >= min_h:
z_next = current_z + h
if z_next > R: z_next = R
r_next = math.sqrt(R**2 - z_next**2)
if (r_curr - r_next) <= max_stepover:
break # Good height
h -= 0.05 # Reduce step
if h < min_h: h = min_h # Clamp
# Print Layer at current_z + h
current_z += h
if current_z > R: break
r = math.sqrt(R**2 - current_z**2)
# Draw circle at this Z
# E calculation: Area = Width * Height
# E_per_mm = (0.4 * h) / Filament_Area
e_factor = (0.4 * h) / 2.4 # Approx
f.write(f"G1 Z{current_z:.3f} F3000\n")
f.write(f"G1 X{r:.3f} Y0 F9000\n") # Move to start
# ... Draw Circle ...
f.write("G28 X0 Y0\n")
12. Stretch Challenge
Challenge: Implement Adaptive Width.
Instead of changing height, change the Extrusion Width (Flow).
Thick lines for infill (fast).
Thin lines for outer walls (detail).
This is "Arachne" engine logic (Cura).
Hint: You need to vary the spacing between lines too.