
What is string art?
String art is a technique that involves weaving threads between fixed points/nails to form patterns by playing with the manner in which threads intersect each other. These fixed-points/nails are typically arranged along the edge of a circular frame and by connecting specific nails with threads that travel along straight lines, the overlap can be tuned, gradually building up a recognizable image or a pattern. This art form was invented in the late 19th century by Mary Everest Boole, an English mathematician. She came up with this technique as an educational tool to help children understand mathematical concepts such as geometry through hands-on learning.
What makes string art particularly interesting is its use of simple geometric shapes and linear structures to approximate complex forms. Each thread is just a straight line, but by layering many lines at different angles, intricate shapes and gradients can emerge. This process can be thought of as the construction of an image through a series of basic building blocks. In this blog post, we will delve into the mathematical ideas behind string art. We will examine how geometry and linear algebra play a crucial role in determining the best arrangement of threads to approximate a given image. Additionally, we will provide a step-by-step explanation of an algorithm that automates the process, making it easier to design and recreate string art using computational tools.

Mathematical foundation
Representation of threads as basis functions
Each thread is defined as a line segment connecting two points on the circle. Mathematically, the equation of a line between two points and is given by:

A visual representation of the thread intensity matrix for a single thread (denoted by blue line) connected between two nails(denoted by red dots). The pixels which have an intersection with the thread are assigned value , while the other pixels of the grid are assigned values .
Thread intensity matrix
Each thread can be represented as a binary vector, where each entry corresponds to a pixel on the grid. If the pixel lies on the thread, the entry is 1; otherwise, it is 0. Collecting all such thread vectors forms the thread intensity matrix, with being the total number of pixels in the image grid, is the total number of threads, determined by the number of connected nails. If there are nails with all of them connected, then , as each pair of nails represents a unique thread. Each column of corresponds to a thread, and each row corresponds to a pixel in the grid. The value is 1 if thread passes through pixel , and 0 otherwise.
Constructing
For each thread connecting nails at and ,
-
Iterate over all pixels in the image grid given by their pixel index.
-
Compute the perpendicular distance of from the thread. To determine whether a pixel lies on this line, we calculate its perpendicular distance from the line, If , the pixel is considered part of the thread.
-
If the distance satisfies the threshold condition, set the corresponding entry as if pixel is on thread , otherwise .
For a small grid and few threads, the thread intensity matrix may look like this: Here each row corresponds to a pixel and each column corresponds to a thread. The ntries are 1 if the thread passes through the pixel. By constructing , we create a mathematical representation of the threads' contributions to the image grid. This matrix serves as the basis for solving the linear system to reconstruct the target image.
Image reconstruction as a linear system
The reconstruction of an image in string art involves finding the
optimal combination of threads that approximates the target image. Let
us define the components and we will explain the reconstruction process
in detail after the definitions.
Target image, : The target image is flattened into a vector
of size , where each entry represents the
grayscale intensity of a pixel. The goal is to approximate
using the contributions of the threads.
Thread weights, : The vector of size
contains the weights of the threads. Each weight determines the
intensity or contribution of the thread to the reconstruction. These
weights capture the importance of a specific feature in the image we
would like to reconstruct and will become important soon.
Linear system representation: We can immediately see that by
multiplying and , we get a flattened version of an image.
The multiplication here simply telling us that the image is
constructed by a sum of threads from with weights . The
reconstructed image is given by,
where is the thread
intensity matrix of size , and , is the the weight
vector of size . The objective is to find such
that the reconstructed image closely matches the target
image .
Minimizing reconstruction error:
Our goal is to construct a target image by a set of threads. The error between the constructed and target image is measured using the Euclidean norm give by, The optimal weights minimize this error for a given , This is a standard least squares problem, where the solution ensures the best possible approximation of in terms of the thread contributions. By solving this optimization problem, we determine how much each thread contributes to the final reconstructed image.
Solving the optimization problem
The problem of minimizing the quadratic error, can be solved mathematically using linear algebra. In our application, is the thread matrix composed of column vectors representing the contribution of each thread (or line) in the image, and is the flattened target image.
Objective function
The quadratic/squared error can be written as, Expanding the product gives, Since is a constant and does not depend on , it can be ignored during minimization.
Gradient of the objective function
To find the optimal weight vector that minimizes , we set the gradient with respect to equal to zero, Dividing by 2, we get the normal equation, If is invertible, the optimal weight vector can be computed as, In cases where is singular or ill-conditioned, the Moore-Penrose pseudoinverse provides a robust alternative, with denoting the pseudoinverse of .
Reconstruction
Once the weight vector is obtained, the reconstructed image is
formed as, Reshaping
back into the original grid produces
the final string art representation.
This approach illustrates how linear algebra and numerical optimization
methods can be harnessed to approximate complex images using simple
geometric primitives.

Reconstructed string art from an input PNG image using the technique described here. The left side shows the target image , while the right side demonstrates its reconstruction using weighted thread patterns.
Conclusion
String art beautifully combines art and mathematics. By understanding
its geometric and algebraic principles, you can create stunning
reconstructions of complex images. Do experiment with different
configurations, numbers of nails, and target images to unleash your
creativity with the python
code attached here!