Filled Curves

One user asked me how to fill the area between two functions. That is not difficult, but you need to define the path around the area to be filled manually.

>t=linspace(0,2pi,500); s=exp(-t^2);
>t1=fliplr(t); s1=sin(t1); // t1 is t in reverse order
>plot2d(t|t1,s|s1,>filled,style="/"); ...

We define an array of t-values and with that the values s of the first function. Then we reverse the order of the t-values and define the values of the second function. We append everything and call the plot2d function for a filled polygon. The fill rule automatically fills those places in the plane, where the path runs around an odd number of times.

The second plot2d command simply draws a curve around the area.

The result is the following.


2 Gedanken zu „Filled Curves

  1. Paul Mayer

    I wanted to fill a closed curve in the complex plane, and I found I could do it by a similar method. plot2d(re(Z_Z1),im(Z_Z1),>filled,style=“/“);
    where Z is the complex curve in the counterclockwise direction, and Z1 is the same curve in reverse direction.
    By the way, the indexed reference page on the website does not list the function ‚extrema‘, a very useful function I found reading one of your examples.

    1. mga010 Beitragsautor

      Thanks for the hint with the missing docs for extrema().

      Also plot2d(z,>filled) should really fill the curve without having to say plot(re(z),im(z),>filled). You do not have to need to go back and forth.


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.