07-13-2020, 05:15 PM
(07-13-2020, 06:15 AM)Ottia Tuota Wrote: The plugin is slow because of the approximation that is needed. If the source path is a Bezier curve of degree 3, the transformation makes it into a curve of degree 9. To draw it with Bezier curves, an approximation must be used. To that end, the plugin uses my own algorithm (that certainly should be much better and faster).
The simple algorithm is fast since it is simple. It does not even try to approximate. If you choose the algorithm by putting the input number =1, it uses the following simple rule: When it sees an arc that should be drawn, it sets the end points exactly right, and it sets the tangent directions at the end points exactly right. But the handle lengths are set simply to be 1/3 of the chord length. If the arc curves only mildly, the result may be good, but it may also be quite wrong. The simple algorithm does not care. I shall make an example picture for you when I have the time.
If you choose the simple algorithm by putting the input number >1, what happens is that the algorithm first subdivides the arc into smaller subarcs, and then it uses the simple rule on the subarcs. So the number of control points grows. Try to put input =8 and see the result.
The slow algorithm ideally gives good approximation with only a small number of control points.
Here is an example picture trying to show what a simple algorithm and the good algorithm do.
The Path to be transformed is the slightly curvy grid. Each arc is a separate stroke with one anchor at each end. The picture shows the transformed path obtained from the simple algorithm with the input numbers 1,2,4, and also from the good algorithm (input number = 0). The Shaper is deliberately chosen to be difficult (large curvatures).
- Algorithm=1: Terribly wrong. Here the simple algorithm adds no new control points. It merely maps the original anchors and then uses the 1/3 rule to construct the handles. No effort done to approximate the right curve. (By the 1/3 rule I mean the rule that handle lengths are set to 1/3 of the chord length.)
- Algorithm=2: Much better but faults are easy to spot. Here the algorithm first makes a subdivision on each segment and only after that uses the 1/3 rule.
- Algorithm=4: Seen in this size already very good but zoomed in one still sees faults. And the cost is that there are still more control points.
- Algorithm=0: The good but slow algorithm.
I also made the experiment (not shown in the picture) that I let the plugin draw two of these cases on top of each other: the case algorithm=0 and the case algorithm=4. That way I could compare the results, and I saw that in some spots there were clear discrepancies. Then I did the same with algorithm=0 and algorithm=8, and I saw no differences in the curves, so it is clear that the approximation algorithm (input=0) did very good work. But the path from algorithm=8 was literally covered by anchors. The conclusion: The good and slow algorithm produced a good result even if slowly.