Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for connecting nails on a board with a string

I want to know whether there exists an existing algorithm for this problem or if it can be mapped to an existing one.

Problem

You are in 2D and want to make some string art using nails on wooden board. For that, you start at a certain nail from the set, all of which are irregularly placed on the board. You then linearly move in discrete steps around the nail board until you reach the end nail. Now, you tighten the string and want to know the path of the string and also which nails the string touches.

Output: Path of the tightened string and its nails.

Example: The orange path is the line that you took around the board. The green line is the final tightened string. Note that direct connections like the start with the nail X are illegal because of the taken path.

Example

An alternative analogy: You fix a rope around a tree in a wood. Then you dash around the trees in linear pieces. You stop at a certain tree and pull really hard at the rope, so it is tightened.

The problem seems a shortest path problem, but with an extra constraint, i.e. only some nodes/nails may be used.

like image 705
Close Call Avatar asked Sep 28 '20 08:09

Close Call


People also ask

What can I use instead of nails for string art?

Use screws instead of nails, which will give a rustic and almost industrial feel to your string art. You can use a corkboard or foam as your can and push pins instead of nails for some kid-friendly string art. Can String Art be Done on Canvas?

How does the algorithm decide which nail color to wrap around?

The algorithm starts from a random nail and then determines the best next nail to wrap around by drawing a line from that nail to every other nail and choosing the darkest one based on the darkness of the image underneath that little line.

How do you keep the string from coming off the nail?

It was a lot of stringing. You have to make sure your string is taught so that it doesn't slip over the nail and come off. But you don't even have to pull so hard as to tug on the nails themselves.

How to make string art at home?

But you can choose any type of flat-topped nail you like. Embroidery thread, which comes in almost any color you can imagine, to create personalized string art. For a more natural or rustic look, you could use natural jute twine or a macrame cord. A hammer which isn’t too heavy so it is easy to manage.


1 Answers

Potential Solution proposed by David Eisenstat:

Shortest (Homotopic) Paths in Polygons (see https://jeffe.cs.illinois.edu/teaching/comptop/2009/notes/shortest-homotopic-paths.pdf)

Here, we are applying the algorithm to the original example.

Step 1 : Crossing Sequences

Using Delaunay triangulation we can get the polygon P from the input nails. Then, we name all the triangle crossings (see image) and write down the sequence of the path.

Polygon P and the path crossing triangles.

Result: ABCBDEFGHIJKLMNOPPQRSTU

Step 2 : Reduction

Removing unncessary loops:

ABCCBDEFGHIJKLMNOPPQRSTU

--> ABBDEFGHIJKLMNOQRSTU

--> ADEFGHIJKLMNOQRSTU

Step 3 : Sleeve

The sleeve is just all triangles in the reducing crossing sequence "glued" together in order.

Step 4 : Funnel

You basically look at every diagonal of the funnel from the start and iteratively determine the shortest path up to a certain point until you reach the end point.

Additional notes: The paper advises to not use these steps explicitly in order, because you can do them in one go. Also, the algorithm can work with loops with some modifications.

like image 171
Close Call Avatar answered Oct 07 '22 10:10

Close Call