trace patterns such that each node is visited only

2019-03-22 07:50发布

Here is my problem which I am trying to solve since one complete year. With no success till end of the year. I have to seek help and a concrete solutions from the stackoverflow experts.

My problem statement:

I have been working with some design patterns which I want to trace if eulerian path exist(as shown in below gifs), programmatically. Below are the patterns and the way I wanna draw them(gifs).

What I wanna achieve:

Give the design pattern images as input. I want trace the design pattern image in a single stroke as shown in the gifs(gifs animations are just examples of how the patterns is drawn in single stroke). Once I get the x and y coordinates of the image in single stroke fashion(eulerian path). I will feed those coordinates to my program to just trace those coordinates.

Thing to be noted in the animation:

1) basically its an undetected graph (the nodes being the vertices of your shapes, the edges if exists being the strokes between 2 vertices). (eulerian path)

Here are the 15 unique shapes which I used to build the patterns with:

enter image description here

I have more then 400 patterns(3 patterns already shown below) and till now I am not able to find a generic solution for this. I have manually got the x y coordinates of the patterns and placed it in sequence. But that is not at all scalable.

How to trace the patterns such that each node is visited only once ?:

1st kind of pattern and the way it should be drawn:

enter image description here

enter image description here

2nd kind of pattern and the way it should be drawn:

enter image description here

enter image description here

3rd kind of pattern and the way it should be drawn:

enter image description here

enter image description here

1条回答
萌系小妹纸
2楼-- · 2019-03-22 08:46

Perhaps you can look into the traveling salesman problem if your still struggling with the above. TSP visits cities only once. And if in your case each node is a crossing for your strike-through then this might help.

Check here for the python code to look at. I've checked and the print statement looks nice and structured. Well done cMinor!

Edit based on discussion: file 1, file2, file3.

查看更多
登录 后发表回答