The Math Behind the String Art

How does a computer know how to recreate a portrait using only a single, continuous thread? It’s not magic—it’s a combination of geometry, integral calculus principles, and a "greedy" optimization algorithm.

The Core Principle: Subtractive Reconstruction

Instead of thinking about where to add black lines, the algorithm looks at the original image and tries to "erase" the darkness by placing thread over it. This is an iterative process that follows these logic steps:

Is it a Radon Transform?

If you are familiar with medical imaging (like CT scans), you might recognize the similarity. A CT scan uses the Radon Transform to reconstruct a 3D body from 2D projections. While our algorithm uses the same fundamental math—calculating the density of a line—it works in reverse. It is an Iterative Matching Pursuit that approximates your photo by picking the best "chords" from a circular dictionary of possibilities.

Choosing the Right Photo

The algorithm is clever, but it has its limitations. For the best results, keep these "physics" of string art in mind:

good-bad images
A good and a bad image for generating pattern.
  • Display artifacts: Your screen and this webpage also have limited resolution so the shown picture can have patterns like the below image has. I generated it from a solid black image, the patterns that you see only emerged due to the limited resolution. You won't see this pattern in the reality. Maybe it's a Moiré pattern, but I'm not sure.
  • moire pattern on black image
    Artifacts on the pattern generated from a solid black image.