01-29-2022, 07:56 AM
I continue with the plugin "Replicate path along another path". Here I first explain a little the idea behind the plugin. Somebody may be interested. Then I mention some problems you may encounter.
The idea behind the plugin very roughly
Very much simplified the idea is as follows. Let tapering=0. Assume that the Base path is the red horizontal line segment and the Source path is the upright line segment in this picture:
Imagine there a coordinate system where the end points of Base are (0,0) and (1,0). Let (x,y) be the coordinates of the uppermost point of Source. Then the length of Source is y and it is located at x-coordinate x. We should map the Source somehow to the Target as several copies. Let us first look at one copy only. And let us look how the point (x,y) is mapped.
We find on the Target a point based on x and the number of the copy (no details now). From that point we shoot up a perpendicular. From that perpendicular we take a point F(x,y) at distance=y scaled suitably. That point F(x,y) is to where (x,y) is mapped.
And here is the picture when we make several copies. The procedure for each copy is the same except that the chosen point on the Target varies.
And that was the basic idea in how the mapping of points is done. However, this is not nearly all since we are making paths, not raster pictures. But I stop here.
Problems
The next picture tries to show two possible problems:
If there is too tight a bend the pattern starts to fold on itself. This problem is inherent in the task, and solving it would require a completely different approach, a quite different way to do the mapping. And then the resulting paths would look quite different.
If the Target is not smooth the result may be non-sensical. It can even be something very wild. This problem is probably partly due to my implementation.
To avoid such difficulties: In the Target path avoid:
The best remedy is to correct such faults manually, unless one is willing to modify the Target path (in this example it would help to make the Target very straight at the problematic stroke end).
Remark
Gimp has the tool "Text along path". Its working is so similar that I think somebody might have taken its code and made it into a tool "Path along path" or "Replicate path along path". Then no need for anybody to write 2600 lines of Python for the same job. That nobody has done it(?) or published(?) might be due to precisely such difficulties: the tool would not be so nicely behaving that it could be offered as a production version. This is just another guess.
The idea behind the plugin very roughly
Very much simplified the idea is as follows. Let tapering=0. Assume that the Base path is the red horizontal line segment and the Source path is the upright line segment in this picture:
Imagine there a coordinate system where the end points of Base are (0,0) and (1,0). Let (x,y) be the coordinates of the uppermost point of Source. Then the length of Source is y and it is located at x-coordinate x. We should map the Source somehow to the Target as several copies. Let us first look at one copy only. And let us look how the point (x,y) is mapped.
We find on the Target a point based on x and the number of the copy (no details now). From that point we shoot up a perpendicular. From that perpendicular we take a point F(x,y) at distance=y scaled suitably. That point F(x,y) is to where (x,y) is mapped.
And here is the picture when we make several copies. The procedure for each copy is the same except that the chosen point on the Target varies.
And that was the basic idea in how the mapping of points is done. However, this is not nearly all since we are making paths, not raster pictures. But I stop here.
Problems
The next picture tries to show two possible problems:
If there is too tight a bend the pattern starts to fold on itself. This problem is inherent in the task, and solving it would require a completely different approach, a quite different way to do the mapping. And then the resulting paths would look quite different.
If the Target is not smooth the result may be non-sensical. It can even be something very wild. This problem is probably partly due to my implementation.
To avoid such difficulties: In the Target path avoid:
- too tight bends;
- anchors where the path is not smooth;
- zero length handles anywhere;
- too abrupt changes of curvature, for example "hooks" at stroke ends.
The best remedy is to correct such faults manually, unless one is willing to modify the Target path (in this example it would help to make the Target very straight at the problematic stroke end).
Remark
Gimp has the tool "Text along path". Its working is so similar that I think somebody might have taken its code and made it into a tool "Path along path" or "Replicate path along path". Then no need for anybody to write 2600 lines of Python for the same job. That nobody has done it(?) or published(?) might be due to precisely such difficulties: the tool would not be so nicely behaving that it could be offered as a production version. This is just another guess.