Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parametric curves 2
#3
Now I show how to use the third plugin Parametric curve (read function from file). The details are explained in doc.pdf, so if you are interested, please read it. I show here two examples. The file doc.py contains two other examples.

I don't do much explanations here. For more details and better explanations, please look at doc.pfd.

The GUI is almost the same as for the other two plugins, but instead of functions x(t), y(t), or r(t), it asks for a file.

Example 1: The cochleoid

To follow this example, make a file with the following contents. Note that it must be valid Python code, so care must be taken of indentations for example.
Code:
def function(t):                   # cochleoid
   from cmath import exp as cexp
   try:
       r = sin(t)/t
   except ZeroDivisionError:
       r = 1
   return r*cexp(1j*t)

curve_name = 'cochleoid'
interval = [-10*pi, 10*pi]
closed = False

Save the file as somefile.py to somewhere where it is easily found (desktop perhaps). Open the GUI of the plugin, and there choose the file somefile.py. Press OK. If everything is ok you get the following curve, called the cochleoid:
   
Explanation: The file is valid Python code. There "def function(t):..." implements the function for the cochleoid curve. The "interval = ..." defines which part of the curve will be drawn.

In the definition of the function, I mention a couple of points for those interested: The function must return a complex number (the plane is viewed as the complex number plane). The defining equation for the cochleoid in polar form is r=sin(t)/t. In the code the factor "*cexp(1j*t)" converts it to proper complex-valued function. The exception ZeroDivisionError occurs when t=0, and there the limit value sin(t)/t -> 1 is used.

Example 2: Experimenting

The formula for the cochleoid in polar form is r = sin(t)/t where t is the argument angle (or polar angle = angle from the positive x axis).

Quite by chance I happened to see yesterday a similar formula r = sin(n*t)/sin(t) while surfing in search of something else. Since I now have this system which makes it easy to experiment with such formulas, I had to try this one. I wrote the following piece of code in a file:
Code:
n = 7 # integer > 0

def function(t):
   from cmath import exp as cexp
   try:
       r = sin(n*t)/sin(t)
   except ZeroDivisionError:
       r = n*cos(n*t)/cos(t) # limit by l'Hospital
   return r*cexp(1j*t)

curve_name = 'experiment n='+str(n)

if n%2 == 0:
   interval = [0,pi]
else:
   interval = [0,2*pi]

closed = True

Here n is a parameter, a positive integer. To change it I have to edit it in the file. When we vary n, the curves follow two patterns. With odd n the curve is symmetric both in x and y directions, but with even n the symmetry in x direction is lost. A typical odd case is given by n=7:
   

The larger n, the larger the number of petals. This looks nice, don't you think? I can imagine that from these one could build a pretty ornament. And it is a path, so the user is free to choose any stroking.

If you have any questions, just ask. Notice that this plugin enables you to write complicated functions since you have free hands to do any Python coding. But it may happen that the plugin cannot handle all inputs. It is written by me, after all, and I am not much of a coder, and since I know the inner structures of the plugin with all those ad hoc solutions and fine-tunings, I know that much can fail. If you run into troubles with the plugin, I would be interested to hear about it.
Reply


Messages In This Thread
Parametric curves 2 - by Ottia Tuota - 07-30-2021, 09:04 AM
RE: Parametric curves 2 - by Ottia Tuota - 07-30-2021, 05:06 PM
RE: Parametric curves 2 - by Ottia Tuota - 07-31-2021, 10:25 AM
RE: Parametric curves 2 - by Ottia Tuota - 08-23-2021, 04:30 PM
RE: Parametric curves 2 - by Ottia Tuota - 08-24-2021, 08:54 AM
RE: Parametric curves 2 - by Ottia Tuota - 08-24-2021, 04:06 PM
RE: Parametric curves 2 - by denzjos - 08-24-2021, 06:29 PM
RE: Parametric curves 2 - by Ottia Tuota - 08-25-2021, 12:25 PM
RE: Parametric curves 2 - by PixLab - 08-25-2021, 04:08 PM
RE: Parametric curves 2 - by denzjos - 08-25-2021, 06:41 PM
RE: Parametric curves 2 - by denzjos - 08-26-2021, 03:51 PM
RE: Parametric curves 2 - by denzjos - 08-26-2021, 06:06 PM
RE: Parametric curves 2 - by Ottia Tuota - 08-26-2021, 07:39 PM
RE: Parametric curves 2 - by Ottia Tuota - 09-02-2021, 02:33 PM
RE: Parametric curves 2 - by Ottia Tuota - 09-22-2021, 08:33 AM
RE: Parametric curves 2 - by Ottia Tuota - 09-22-2021, 01:30 PM
RE: Parametric curves 2 - by Ottia Tuota - 10-10-2021, 02:15 PM
RE: Parametric curves 2 - by PixLab - 10-21-2021, 06:41 AM
RE: Parametric curves 2 - by Ottia Tuota - 10-21-2021, 03:40 PM
RE: Parametric curves 2 - by PixLab - 10-22-2021, 04:39 AM

Forum Jump: