Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parametric curves
#1
Hello!

Here are my first two plugins. With them you can draw parametric curves (or polar curves) in Gimp, approximately as Bézier curves. If you go to

http://kmarkku.arkku.net/

and click the link Simple Parametric Curves, and scroll down to the bottom, you find a button to download a .zip file. The items in the .zip file are:

- simple_parametric_curve.py (this is the plugins)
- doc.pdf (the documentation)
- example_files (this is a folder; see the site for explanation).

To install do:

1. Download the .zip file.
2. Unzip it.
3. Put the file simple_parametric_curve.py in your Gimp's plug-ins folder.
4. Restart Gimp.
5. Then the two plugins should appear in Gimp's menu at
     Filters / Render / Parametric curves.
Their names are 'Simple parametric curve' and 'Simple polar curve'.

You had better then start by glancing through what the site tells. Then glance at the file doc.pdf.  If the plugins interest you, you had better read doc.pdf more thoroughly at some point.

The task is to draw a parametric curve. That is what the first plugin, Simple parametric curve, does. The second, Simple polar curve, draws a curve given in polar form. (I assume here that you have some idea what those mean, so I don't explain). By "drawing" I mean that the plugin constructs the curve as a Bézier curve. In Gimp that means a path or a vectors object. So, if you want to stroke the curve, you have to do it yourself.

Since only very few curves can be faithfully represented as a Bézier curve, the produced path is just an approximation of the requested parametric curve.

Inkscape has a tool for such job. But it is even more simple than my plugins. To get an accurate result with it, one often has to make it to put control points densely on the curve. My plugin works in the opposite way: It tries to use only a sparse set of control points. That makes the problem of approximation quite non-trivial. The algorithms are my own.

You may wonder why I call my plugins simple. The reason is that I shall soon be sharing with you a third plugin which is developed much further, works much better, but is more difficult to use. (Though, if you feed the inputs in the GUI and not in an input file, there is not much difference. What these words mean, please see the explanations on the site or in doc.pdf.) I believe that in practice the simple plugins will be the ones most used.

I was hoping to include a picture but it seems that it cannot be uploaded here, only a link to somewhere else. So, please download the .zip file and look at the file doc.pdf there. It has some pictures.

Now I'd like to say a little of my background. I am a mathematician, already retired, who knows very little about computers or coding. Making such plugins came to me as a hobby some years ago. I was hooked and still am. I have been learning Python along the way. I used a much older version of my plugin when I wrote some lecture notes in mathematics as my last task before retirement in 2016. All curves I draw using my own plugin. So the plugin has been applied in a useful job even before publication.

If you have questions or problems with the plugins, please just ask.
Reply
#2
Welcome to the party...

(03-12-2020, 01:21 PM)Ottia Tuota Wrote: I was hoping to include a picture but it seems that it cannot be uploaded here, only a link to somewhere else.

Of course you can... see other posts elsewhere on this forum. The (simple) procedure is explained in the "Attachments" link at the top right of this page.
Reply
#3
Nice work, I tested with it with Gimp 2.10.18 installed on D drive / Windows 10 and the plugins are working (the result is a path) but there is also an error message on the screen : 

   
Reply
#4
That error message does not come from the plugin, I believe. I have the same error messages when I use Gimp from gimp.org, and it comes both when I open Gimp and when i start the plugin. But no such messages come when I use portable Gimp from Partha or Samj. And somebody else has had the same message, see

https://www.reddit.com/r/GIMP/comments/f...h_install/

I really don't know what it is about.


I might as well warn that the plugin (if display messages is set to Yes) does sometimes show frightening error messages in the error console. They can be usually safely ignored as I explain in doc.pdf. They just tell that the plugin encountered some difficulties, but they are usually not fatal since it normally has the trick of going into deeper recursion.

(03-12-2020, 03:04 PM)Ofnuts Wrote: Welcome to the party...

(03-12-2020, 01:21 PM)Ottia Tuota Wrote: I was hoping to include a picture but it seems that it cannot be uploaded here, only a link to somewhere else.

Of course you can...  see other posts elsewhere on this forum. The (simple) procedure is explained in the "Attachments" link at the top right of this page.

Thank you, now I know it. But that picture was no loss. Those in doc.pdf are better.
Reply
#5
Ok, I should have known that this would happen: Soon after publishing the plugin I found a bug. If the starting and ending values are in descending order, the result is wrong.

But I found where the error is, and I shall make the fix tomorrow.
Reply
#6
(03-12-2020, 03:23 PM)denzjos Wrote: Nice work, I tested with it with Gimp 2.10.18 installed on D drive / Windows 10 and the plugins are working (the result is a path) but there is also an error message on the screen :

Likely totally unrelated....
Reply
#7
Trying to do a simple linear spiral with the polar curve script. So, in the GUI;

Code:
r(t)=t/10.
start=0.
end=2*N*pi

For a few turns (N<=5), the result is nice, but around N=8 things start to degrade, this is N=9:

   

At N=12, things are really out of whack:

   

At N=25, you wonder about the validity of your formula:

   


All these with highest accuracy (level 10).

TBH I'm surprised by the low number of anchors, about two anchors per turn, even at level 10.
Reply
#8
(03-12-2020, 06:38 PM)Ottia Tuota Wrote: Ok, I should have known that this would happen: Soon after publishing the plugin I found a bug. If the starting and ending values are in descending order, the result is wrong.

But I found where the error is, and I shall make the fix tomorrow.

I fixed this. The new version is now in the same place. See the first post.
Reply
#9
(03-12-2020, 11:02 PM)Ofnuts Wrote: Trying to do a simple linear spiral with the polar curve script. So, in the GUI;

Code:
r(t)=t/10.
start=0.
end=2*N*pi

For a few turns (N<=5), the result is nice, but around N=8 things start to degrade, this is N=9:


...

TBH I'm surprised by the low number of anchors, about two anchors per turn, even at level 10.

Thanks for trying the plugin.

You are quite right. This is the problem with the simple plugin. The better plugin that I shall publish later will be able to handle such cases right away. The simple plugin needs help from the user.

The problem is explained in Example 2.5 at the end of doc.pdf, and there is also the remedy. To draw a spiral arc you had better not to try arcs longer than 90 degrees. But the simple plugin has no other way to divide the spiral than to split it in two recursively. And I put there a hard-coded limit for the recursion depth, just to avoid infinite loops. If we run your spiral with N=10 setting 'display messages' to Yes, we get in the error console a long list of strange error messages, and the last one is:

The algorithm reached maximum allowed
recursion depth (=4) 16 times
The result may be wrong!

And now the remedy. It is to input a list of custom parameter values. It is possible in the GUI, but easier is to write a file where the inputs are. As follows:
Code:
N=10

def function(t):
   #r(t)=t/10.
   return t/10.

start=0.
end=2*N*pi

interval = [start, end]

custom_params = [k*pi/2 for k in range(4*N)]

scale = 50

Then the result is the following (I try to get a picture here)

   

The idea is that when the plugin gets such a list of custom parameter values, then first, before doing anything else, it divides the curve at those points. Only then it goes to work, doing recusions etc. So when we choose the points so that the arcs between are not more than 90 degrees, the plugin manages well.

There is the field in the GUI: "Chosen values of t ... " (admittedly not very well formulated text) where you could put the list as  pi/2, pi, 3*pi/2, 2*pi, ...  but for large N that is not practical. So make a file where the inputs are. There are also the example files or doc.pdf to look at.

When you write the inputs in a file, then to use the file do: In the GUI click "Read inputs from a file" to Yes, and then use the next field to choose the file. The format of the input file is described in doc.pdf.
Reply
#10
(03-13-2020, 05:03 AM)Ottia Tuota Wrote:
(03-12-2020, 06:38 PM)Ottia Tuota Wrote: Ok, I should have known that this would happen: Soon after publishing the plugin I found a bug. If the starting and ending values are in descending order, the result is wrong.

But I found where the error is, and I shall make the fix tomorrow.

I fixed this. The new version is now in the same place. See the first post.
The fix was not perfect. I made a new one. Hopefully it is now all right. The version is 0.9.2.
Reply


Forum Jump: