Fill the area between two curves

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
10
down vote

favorite
4












Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween library but I just can't get the upper curve right.
enter image description hereenter image description here



Your help is much appreciated. A MWE is as follows



documentclass[margin=10pt]standalone
usepackagetikz
usepackagepgfplots
pgfplotssetcompat=newest
usepgfplotslibraryfillbetween
usetikzlibraryintersections


begindocument
begintikzpicture%[x=1cm, y=1cm]
defrsmall2
defrlarge4
defalpha60
defbeta40
defgamma20
defAoutalpha+gamma-90
defBin270-beta-gamma

pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
pgfmathsetmacroaysin(alpha)*rsmall
pgfmathsetmacrobxrlarge-cos(beta)*rlarge
pgfmathsetmacrobysin(beta)*rlarge

filldraw[name path=arcs, fill=gray!20, thick]
(180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

coordinate (A) at (ax, ay);
coordinate (B) at (bx, by);

draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];


endtikzpicture
enddocument






share|improve this question
























    up vote
    10
    down vote

    favorite
    4












    Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween library but I just can't get the upper curve right.
    enter image description hereenter image description here



    Your help is much appreciated. A MWE is as follows



    documentclass[margin=10pt]standalone
    usepackagetikz
    usepackagepgfplots
    pgfplotssetcompat=newest
    usepgfplotslibraryfillbetween
    usetikzlibraryintersections


    begindocument
    begintikzpicture%[x=1cm, y=1cm]
    defrsmall2
    defrlarge4
    defalpha60
    defbeta40
    defgamma20
    defAoutalpha+gamma-90
    defBin270-beta-gamma

    pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
    pgfmathsetmacroaysin(alpha)*rsmall
    pgfmathsetmacrobxrlarge-cos(beta)*rlarge
    pgfmathsetmacrobysin(beta)*rlarge

    filldraw[name path=arcs, fill=gray!20, thick]
    (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

    coordinate (A) at (ax, ay);
    coordinate (B) at (bx, by);

    draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


    fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];


    endtikzpicture
    enddocument






    share|improve this question






















      up vote
      10
      down vote

      favorite
      4









      up vote
      10
      down vote

      favorite
      4






      4





      Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween library but I just can't get the upper curve right.
      enter image description hereenter image description here



      Your help is much appreciated. A MWE is as follows



      documentclass[margin=10pt]standalone
      usepackagetikz
      usepackagepgfplots
      pgfplotssetcompat=newest
      usepgfplotslibraryfillbetween
      usetikzlibraryintersections


      begindocument
      begintikzpicture%[x=1cm, y=1cm]
      defrsmall2
      defrlarge4
      defalpha60
      defbeta40
      defgamma20
      defAoutalpha+gamma-90
      defBin270-beta-gamma

      pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
      pgfmathsetmacroaysin(alpha)*rsmall
      pgfmathsetmacrobxrlarge-cos(beta)*rlarge
      pgfmathsetmacrobysin(beta)*rlarge

      filldraw[name path=arcs, fill=gray!20, thick]
      (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

      coordinate (A) at (ax, ay);
      coordinate (B) at (bx, by);

      draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


      fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];


      endtikzpicture
      enddocument






      share|improve this question












      Hi I am trying to fill the area between two curves. One curve is two joined arcs, and the other is one freehand curve. The part I want to fill is the white area. I use the fillbetween library but I just can't get the upper curve right.
      enter image description hereenter image description here



      Your help is much appreciated. A MWE is as follows



      documentclass[margin=10pt]standalone
      usepackagetikz
      usepackagepgfplots
      pgfplotssetcompat=newest
      usepgfplotslibraryfillbetween
      usetikzlibraryintersections


      begindocument
      begintikzpicture%[x=1cm, y=1cm]
      defrsmall2
      defrlarge4
      defalpha60
      defbeta40
      defgamma20
      defAoutalpha+gamma-90
      defBin270-beta-gamma

      pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
      pgfmathsetmacroaysin(alpha)*rsmall
      pgfmathsetmacrobxrlarge-cos(beta)*rlarge
      pgfmathsetmacrobysin(beta)*rlarge

      filldraw[name path=arcs, fill=gray!20, thick]
      (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

      coordinate (A) at (ax, ay);
      coordinate (B) at (bx, by);

      draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


      fill[blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2];


      endtikzpicture
      enddocument








      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 23 at 3:28









      noir

      43538




      43538




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          14
          down vote



          accepted










          You only need to add a [reverse] to one of the segments.



          documentclass[margin=10pt]standalone
          usepackagetikz
          usepackagepgfplots
          pgfplotssetcompat=newest
          usepgfplotslibraryfillbetween
          usetikzlibraryintersections


          begindocument
          begintikzpicture%[x=1cm, y=1cm]
          defrsmall2
          defrlarge4
          defalpha60
          defbeta40
          defgamma20
          defAoutalpha+gamma-90
          defBin270-beta-gamma

          pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
          pgfmathsetmacroaysin(alpha)*rsmall
          pgfmathsetmacrobxrlarge-cos(beta)*rlarge
          pgfmathsetmacrobysin(beta)*rlarge

          filldraw[name path=arcs, fill=gray!20, thick]
          (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

          coordinate (A) at (ax, ay);
          coordinate (B) at (bx, by);

          draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


          path[%draw=red,thick,
          fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];


          endtikzpicture
          enddocument


          enter image description here



          How can one debug this? Just draw curves with arrows on the segments in question. Here one would add



          draw[red,thick,-latex,
          intersection segments=of=unduloid and arcs,sequence=L2];

          draw[blue,thick,-latex,
          intersection segments=of=unduloid and arcs,sequence=R2];


          and then get



          enter image description here



          This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.



          ADDENDUM: In this situation you do not really need all the segments nor the fillbetween library. Personally I would also refrain from redefining alpha, beta etc. since you may need these Greek symbols.



          documentclass[margin=10pt]standalone
          usepackagetikz
          usetikzlibrarycalc


          begindocument
          begintikzpicture%[x=1cm, y=1cm]
          defrsmall2
          defrlarge4
          defmyalpha60
          defmybeta40
          defgamma20
          defAoutmyalpha+gamma-90
          defBin270-mybeta-gamma


          filldraw[fill=gray!20, thick]
          (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

          coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
          coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);

          draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
          arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;

          endtikzpicture
          enddocument


          enter image description here






          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "85"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f447265%2ffill-the-area-between-two-curves%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            14
            down vote



            accepted










            You only need to add a [reverse] to one of the segments.



            documentclass[margin=10pt]standalone
            usepackagetikz
            usepackagepgfplots
            pgfplotssetcompat=newest
            usepgfplotslibraryfillbetween
            usetikzlibraryintersections


            begindocument
            begintikzpicture%[x=1cm, y=1cm]
            defrsmall2
            defrlarge4
            defalpha60
            defbeta40
            defgamma20
            defAoutalpha+gamma-90
            defBin270-beta-gamma

            pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
            pgfmathsetmacroaysin(alpha)*rsmall
            pgfmathsetmacrobxrlarge-cos(beta)*rlarge
            pgfmathsetmacrobysin(beta)*rlarge

            filldraw[name path=arcs, fill=gray!20, thick]
            (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

            coordinate (A) at (ax, ay);
            coordinate (B) at (bx, by);

            draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


            path[%draw=red,thick,
            fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];


            endtikzpicture
            enddocument


            enter image description here



            How can one debug this? Just draw curves with arrows on the segments in question. Here one would add



            draw[red,thick,-latex,
            intersection segments=of=unduloid and arcs,sequence=L2];

            draw[blue,thick,-latex,
            intersection segments=of=unduloid and arcs,sequence=R2];


            and then get



            enter image description here



            This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.



            ADDENDUM: In this situation you do not really need all the segments nor the fillbetween library. Personally I would also refrain from redefining alpha, beta etc. since you may need these Greek symbols.



            documentclass[margin=10pt]standalone
            usepackagetikz
            usetikzlibrarycalc


            begindocument
            begintikzpicture%[x=1cm, y=1cm]
            defrsmall2
            defrlarge4
            defmyalpha60
            defmybeta40
            defgamma20
            defAoutmyalpha+gamma-90
            defBin270-mybeta-gamma


            filldraw[fill=gray!20, thick]
            (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

            coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
            coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);

            draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
            arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;

            endtikzpicture
            enddocument


            enter image description here






            share|improve this answer


























              up vote
              14
              down vote



              accepted










              You only need to add a [reverse] to one of the segments.



              documentclass[margin=10pt]standalone
              usepackagetikz
              usepackagepgfplots
              pgfplotssetcompat=newest
              usepgfplotslibraryfillbetween
              usetikzlibraryintersections


              begindocument
              begintikzpicture%[x=1cm, y=1cm]
              defrsmall2
              defrlarge4
              defalpha60
              defbeta40
              defgamma20
              defAoutalpha+gamma-90
              defBin270-beta-gamma

              pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
              pgfmathsetmacroaysin(alpha)*rsmall
              pgfmathsetmacrobxrlarge-cos(beta)*rlarge
              pgfmathsetmacrobysin(beta)*rlarge

              filldraw[name path=arcs, fill=gray!20, thick]
              (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

              coordinate (A) at (ax, ay);
              coordinate (B) at (bx, by);

              draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


              path[%draw=red,thick,
              fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];


              endtikzpicture
              enddocument


              enter image description here



              How can one debug this? Just draw curves with arrows on the segments in question. Here one would add



              draw[red,thick,-latex,
              intersection segments=of=unduloid and arcs,sequence=L2];

              draw[blue,thick,-latex,
              intersection segments=of=unduloid and arcs,sequence=R2];


              and then get



              enter image description here



              This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.



              ADDENDUM: In this situation you do not really need all the segments nor the fillbetween library. Personally I would also refrain from redefining alpha, beta etc. since you may need these Greek symbols.



              documentclass[margin=10pt]standalone
              usepackagetikz
              usetikzlibrarycalc


              begindocument
              begintikzpicture%[x=1cm, y=1cm]
              defrsmall2
              defrlarge4
              defmyalpha60
              defmybeta40
              defgamma20
              defAoutmyalpha+gamma-90
              defBin270-mybeta-gamma


              filldraw[fill=gray!20, thick]
              (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

              coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
              coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);

              draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
              arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;

              endtikzpicture
              enddocument


              enter image description here






              share|improve this answer
























                up vote
                14
                down vote



                accepted







                up vote
                14
                down vote



                accepted






                You only need to add a [reverse] to one of the segments.



                documentclass[margin=10pt]standalone
                usepackagetikz
                usepackagepgfplots
                pgfplotssetcompat=newest
                usepgfplotslibraryfillbetween
                usetikzlibraryintersections


                begindocument
                begintikzpicture%[x=1cm, y=1cm]
                defrsmall2
                defrlarge4
                defalpha60
                defbeta40
                defgamma20
                defAoutalpha+gamma-90
                defBin270-beta-gamma

                pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
                pgfmathsetmacroaysin(alpha)*rsmall
                pgfmathsetmacrobxrlarge-cos(beta)*rlarge
                pgfmathsetmacrobysin(beta)*rlarge

                filldraw[name path=arcs, fill=gray!20, thick]
                (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

                coordinate (A) at (ax, ay);
                coordinate (B) at (bx, by);

                draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


                path[%draw=red,thick,
                fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];


                endtikzpicture
                enddocument


                enter image description here



                How can one debug this? Just draw curves with arrows on the segments in question. Here one would add



                draw[red,thick,-latex,
                intersection segments=of=unduloid and arcs,sequence=L2];

                draw[blue,thick,-latex,
                intersection segments=of=unduloid and arcs,sequence=R2];


                and then get



                enter image description here



                This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.



                ADDENDUM: In this situation you do not really need all the segments nor the fillbetween library. Personally I would also refrain from redefining alpha, beta etc. since you may need these Greek symbols.



                documentclass[margin=10pt]standalone
                usepackagetikz
                usetikzlibrarycalc


                begindocument
                begintikzpicture%[x=1cm, y=1cm]
                defrsmall2
                defrlarge4
                defmyalpha60
                defmybeta40
                defgamma20
                defAoutmyalpha+gamma-90
                defBin270-mybeta-gamma


                filldraw[fill=gray!20, thick]
                (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

                coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
                coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);

                draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
                arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;

                endtikzpicture
                enddocument


                enter image description here






                share|improve this answer














                You only need to add a [reverse] to one of the segments.



                documentclass[margin=10pt]standalone
                usepackagetikz
                usepackagepgfplots
                pgfplotssetcompat=newest
                usepgfplotslibraryfillbetween
                usetikzlibraryintersections


                begindocument
                begintikzpicture%[x=1cm, y=1cm]
                defrsmall2
                defrlarge4
                defalpha60
                defbeta40
                defgamma20
                defAoutalpha+gamma-90
                defBin270-beta-gamma

                pgfmathsetmacroax-rsmall+cos(alpha)*rsmall
                pgfmathsetmacroaysin(alpha)*rsmall
                pgfmathsetmacrobxrlarge-cos(beta)*rlarge
                pgfmathsetmacrobysin(beta)*rlarge

                filldraw[name path=arcs, fill=gray!20, thick]
                (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

                coordinate (A) at (ax, ay);
                coordinate (B) at (bx, by);

                draw[name path=unduloid, thick] (A) to[out=Aout, in=Bin] (B);


                path[%draw=red,thick,
                fill=blue!20,intersection segments=of=unduloid and arcs,sequence=L2--R2[reverse]];


                endtikzpicture
                enddocument


                enter image description here



                How can one debug this? Just draw curves with arrows on the segments in question. Here one would add



                draw[red,thick,-latex,
                intersection segments=of=unduloid and arcs,sequence=L2];

                draw[blue,thick,-latex,
                intersection segments=of=unduloid and arcs,sequence=R2];


                and then get



                enter image description here



                This means that the paths start and end at the same points. To fix this, i.e. to produce a cycle, you have to run through one of the paths in the reverse direction. If you don't, TikZ will close the path on its own by a straight line. That's why you got the straight line for one of the bounding curves.



                ADDENDUM: In this situation you do not really need all the segments nor the fillbetween library. Personally I would also refrain from redefining alpha, beta etc. since you may need these Greek symbols.



                documentclass[margin=10pt]standalone
                usepackagetikz
                usetikzlibrarycalc


                begindocument
                begintikzpicture%[x=1cm, y=1cm]
                defrsmall2
                defrlarge4
                defmyalpha60
                defmybeta40
                defgamma20
                defAoutmyalpha+gamma-90
                defBin270-mybeta-gamma


                filldraw[fill=gray!20, thick]
                (180:2*rsmall) arc (180:0:rsmall) arc (180:0:rlarge);

                coordinate (A) at ($(-rsmall,0)+(myalpha:rsmall)$);
                coordinate (B) at ($(rlarge,0)+(180-mybeta:rlarge)$);

                draw[red,fill=blue!20, thick] (A) to[out=Aout, in=Bin] (B)
                arc(180-mybeta:180:rlarge) arc(0:myalpha:rsmall) -- cycle;

                endtikzpicture
                enddocument


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 23 at 4:03

























                answered Aug 23 at 3:36









                marmot

                55.4k460121




                55.4k460121



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f447265%2ffill-the-area-between-two-curves%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    Long meetings (6-7 hours a day): Being “babysat” by supervisor

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    Confectionery