07-30-2021, 09:04 AM

I return to my old love: parametric curves. You may remember that I wrote a plugin to draw parametric curves as Gimp's paths approximately. Now the plugin has a new version. It is so big overhaul that I prefer to start a new thread. I wish everybody would just forget the old one.

The new version 2.1 has a new approximation algorithm. Meanwhile I have learned something about plugin writing, and I also had my eye on how the extension Parametric Curves is done in Inkscape, and I hope that I now managed to make my plugin a little more user-friendly. Anyway, it is no longer so loaded with options nobody wants.

If you have in your plugins folder files 'parametric_curves.py' and 'simple_parametric_curve.py', please delete those. To get the new version (2.1), click the link

http://kmarkku.arkku.net/Parametric_curv...aster.html

scroll down and download the file for Parametric curves; this gives you the .zip file parametric_curves_2_1.zip. (There is another download button for Special curves, an update of an old version, but I talk now only about the Parametric curves.)

The .zip file parametric_curves_2_1.zip contains one file parametric_curve.py and a small file doc.pdf. When you unzip the .zip file and move the .py file to your user's plug-ins folder, and restart Gimp, you find in the menu at

Filters > Render > Parametric curves

three plugins:

The documentation file doc.pdf contains explanations and instructions. They are probably useful only if you try the third plugin. Otherwise you don't lose much if you skip the documentation and just go experimenting.

The first plugin is the basic form, and I talk only about that in this post. The other two I shall explain later.

Open the first plugin Parametric curve (cartesian). If you let the default values in the GUI be as they are and just press OK, you get a half circle, as large as can be fitted on the screen. I don't show it here: you know what a half circle is.

To get a better example, put in the GUI the following:

[attachment=6453]

Changes from the defaults are:

name = astroid

x(t) = cos(t)**3

y(t) = sin(t)**3

start value for t = 0 (this is the same as default)

end value for t = 2*pi

the curve is closed

padding = 50

Then on the screen you get an astroid, fitted to fill the screen with a little padding. And it is a path, so all stroking is left to the user.

[attachment=6454]

That is the idea. If you keep 'fit to window' as Yes, you get as large a curve as fits on the screen and the next field enables you to put some padding. But clicking 'fit to window' to No, you can control the size and placement with the three inputs 'x of the origo', 'y of the origo' and 'scale'.

<...skip on first reading...>

There is one input which you can usually safely just ignore: custom parameter values. But I explain the idea for once: Consider the astroid example. There are four cusps. The plugin puts one anchor at each cusp. Those anchors should be set rather precisely to obtain a faithful rendering of the astroid. But how does the plugin find the cusps? It cannot compute derivatives (which would bring the problem down to solving equations). No, the only thing it can do is to run along the curve and examine it at very many close points. That is what it does and that is how it finds cusps (or inflection points or whatever). You understand that that is necessarily inaccurate. So, the idea in those custom points is that the user can help the plugin in its work. The user can list the parameter values (pi/2, pi, 3*pi/2) which give three of the cusps (the fourth is the starting or ending value of t, so the plugin knows it anyway). When the plugin is given those exact parameter values it places anchors at those exact spots and the result will be more accurate.

But in its current form the plugin is so good in finding cusps on its own (or inflection points or whatever) that you can usually ignore this difficulty. But it is good to know just in case: with custom points you can force the plugin to place anchors at some particular points. Then those points will be exactly on the right curve. Between the anchors the curve will only approximate the true curve.

</...skip on first reading...>

You may recall that the goal of this plugin is: Given a parametric curve,

1. approximate it with a path (a composite Bezier curve);

2. try to do this very accurately; and

3. do this with only a small number of control points.

Requirements 2 and 3 are contradictory, but at the moment I am rather pleased with how the plugin works.

If you try the plugin with complicated curves you are likely to find trouble cases where something goes wrong. I shall be grateful if you report those: the functions, the interval, custom points (if any), and any error messages.

The new version 2.1 has a new approximation algorithm. Meanwhile I have learned something about plugin writing, and I also had my eye on how the extension Parametric Curves is done in Inkscape, and I hope that I now managed to make my plugin a little more user-friendly. Anyway, it is no longer so loaded with options nobody wants.

If you have in your plugins folder files 'parametric_curves.py' and 'simple_parametric_curve.py', please delete those. To get the new version (2.1), click the link

http://kmarkku.arkku.net/Parametric_curv...aster.html

scroll down and download the file for Parametric curves; this gives you the .zip file parametric_curves_2_1.zip. (There is another download button for Special curves, an update of an old version, but I talk now only about the Parametric curves.)

The .zip file parametric_curves_2_1.zip contains one file parametric_curve.py and a small file doc.pdf. When you unzip the .zip file and move the .py file to your user's plug-ins folder, and restart Gimp, you find in the menu at

Filters > Render > Parametric curves

three plugins:

- Parametric curve (cartesian)

- Parametric curve (polar)

- Parametric curve (read function from file)

The documentation file doc.pdf contains explanations and instructions. They are probably useful only if you try the third plugin. Otherwise you don't lose much if you skip the documentation and just go experimenting.

The first plugin is the basic form, and I talk only about that in this post. The other two I shall explain later.

Open the first plugin Parametric curve (cartesian). If you let the default values in the GUI be as they are and just press OK, you get a half circle, as large as can be fitted on the screen. I don't show it here: you know what a half circle is.

To get a better example, put in the GUI the following:

[attachment=6453]

Changes from the defaults are:

name = astroid

x(t) = cos(t)**3

y(t) = sin(t)**3

start value for t = 0 (this is the same as default)

end value for t = 2*pi

the curve is closed

padding = 50

Then on the screen you get an astroid, fitted to fill the screen with a little padding. And it is a path, so all stroking is left to the user.

[attachment=6454]

That is the idea. If you keep 'fit to window' as Yes, you get as large a curve as fits on the screen and the next field enables you to put some padding. But clicking 'fit to window' to No, you can control the size and placement with the three inputs 'x of the origo', 'y of the origo' and 'scale'.

<...skip on first reading...>

There is one input which you can usually safely just ignore: custom parameter values. But I explain the idea for once: Consider the astroid example. There are four cusps. The plugin puts one anchor at each cusp. Those anchors should be set rather precisely to obtain a faithful rendering of the astroid. But how does the plugin find the cusps? It cannot compute derivatives (which would bring the problem down to solving equations). No, the only thing it can do is to run along the curve and examine it at very many close points. That is what it does and that is how it finds cusps (or inflection points or whatever). You understand that that is necessarily inaccurate. So, the idea in those custom points is that the user can help the plugin in its work. The user can list the parameter values (pi/2, pi, 3*pi/2) which give three of the cusps (the fourth is the starting or ending value of t, so the plugin knows it anyway). When the plugin is given those exact parameter values it places anchors at those exact spots and the result will be more accurate.

But in its current form the plugin is so good in finding cusps on its own (or inflection points or whatever) that you can usually ignore this difficulty. But it is good to know just in case: with custom points you can force the plugin to place anchors at some particular points. Then those points will be exactly on the right curve. Between the anchors the curve will only approximate the true curve.

</...skip on first reading...>

You may recall that the goal of this plugin is: Given a parametric curve,

1. approximate it with a path (a composite Bezier curve);

2. try to do this very accurately; and

3. do this with only a small number of control points.

Requirements 2 and 3 are contradictory, but at the moment I am rather pleased with how the plugin works.

If you try the plugin with complicated curves you are likely to find trouble cases where something goes wrong. I shall be grateful if you report those: the functions, the interval, custom points (if any), and any error messages.