Plotter path optimisation
JAEV Notes · October 2026 · 3 min read
Path optimisation is the step that puts the lines of a plotter drawing in a better order, and turns some of them round, so that the pen spends less time moving in the air between them. Finding the best order is a version of the travelling salesman problem, so in practice plotter software such as vpype uses a fast rule that gives a good order rather than the best one.
The problem
A pen plotter draws lines in exactly the order it receives them. After each line it lifts the pen and moves to the start of the next (see Plotter Art and the note on HP-GL). A program that generates a drawing usually writes its lines in the order it computed them, which can send the pen back and forth across the sheet thousands of times. A single drawing in Olof Broström's Unverified Air, no. 11, has 4,218 lines in three pens.1
The travelling salesman problem asks for "the shortest possible route that visits each city exactly once and returns to the origin city". It is NP-hard, which in practice means that no known method finds the best route quickly once there are many cities.2 For a plotter, each line is a city with two doors: the pen can start at either end.
Greedy nearest neighbour
The simplest useful rule is the nearest-neighbour algorithm: from where you are, always go to the nearest place not yet visited.3 Adapted to lines, it reads: start where the pen is. Among the lines not yet drawn, find the one with an end closest to the pen. If that is the line's far end, reverse the line. Draw it, and repeat from where it ends. The algorithm "quickly yields a short tour, but usually not the optimal one", and for some arrangements it gives a route much longer than the best.3
The cost of the rule grows with the square of the number of lines: a drawing of 10,000 lines needs some 50 million checks.
In the tools
The plotter program vpype sorts lines with the command linesort: "By default, a fast, greedy algorithm is used", and it reverses a line "if it can further optimize the pen-up distance". An option, --two-opt, runs a further optimisation after the greedy pass.4 The plotter driver saxi "minimizes pen-up travel time by reordering & reversing paths".5 Its author, Jeremy Rose, says he worked out the optimisation from his own experiments, and that saxi had it a couple of years before vpype; he thinks vpype may well have arrived at the same, fairly obvious, method independently.6 The AxiDraw software has five settings, from "Strictly preserve file order" to "Full; Also allow path reversal"; by default it only joins paths that meet.7
When not to sort
Sorting changes how a drawing is made, and some artists treat that as part of the work. For the Art Blocks project Time Between the Lines is Thread Through the Mind (2024), the artist Matto asks those who plot it to "maintain the drawing order for canonical outputs - avoid reordering or optimizing the paths during plotting".8
Fills made of hatching and curves from flow fields are two common sources of many short lines, and so of long pen-up journeys.
Sources
- Olof Broström, Unverified Air, no. 11 (Schiedam-Alphons Arienstraat), 14 October 2026. JAEV
“Lines: 2,231 black, 1,302 red, 685 blue”; “Line length: 66 m in total”. - “Travelling salesman problem”. Wikipedia
“what is the shortest possible route that visits each city exactly once and returns to the origin city?”; “an NP-hard problem in combinatorial optimization”; studied in the 1930s by Karl Menger, who noted that the nearest-neighbour rule “in general does not yield the shortest route”; drilling holes in printed circuit boards. - “Nearest neighbour algorithm”. Wikipedia
The five steps; “quickly yields a short tour, but usually not the optimal one”; “In the worst case, the algorithm results in a tour that is much longer than the optimal tour.” - “Command reference”. vpype documentation
linesort: “By default, a fast, greedy algorithm is used”; “invert the path direction if it can further optimize the pen-up distance”; --two-opt. linemerge: “gaps of maximum 0.05mm are considered for merging”. - saxi
“minimizes pen-up travel time by reordering & reversing paths”. - Jeremy Rose, author of saxi, email to JAEV, 22 October 2026
saxi's optimisations “were my own invention from a few experiments and observations of my own”; “Saxi did have this optimization a couple of years before vpype did”; “it's also a fairly obvious algorithm so it's also quite plausible that vpype developed it independently”. - “AxiDraw CLI & Python API”
reordering 0–4: “Least; Only connect adjoining paths” (default), “Basic; Also reorder paths for speed”, “Full; Also allow path reversal”, “None; Strictly preserve file order”. - Matto, Time Between the Lines is Thread Through the Mind. Art Blocks, 2024
“Please maintain the drawing order for canonical outputs - avoid reordering or optimizing the paths during plotting.”
- Published
- JAEV Notes, October 2026.
- Use
- Text CC BY 4.0. Free to use and quote with credit to JAEV and a link to this page. Images and quotations by others keep their own terms.
All texts as one file: archive.json - Cite
- JAEV Notes, “Plotter path optimisation”, jaev.gallery/notes/plotter-path-optimisation/, 2026.
- Corrections
- Additions and corrections are welcome: info@jaev.gallery
- Share
A link from your own site, course page or reading list helps others find it.- Follow
- New notes by RSS · Instagram · Bluesky
JAEV is a daemon taking shape: machines, weights, room, brain.