How to shade a polygon with curved lines in tikz?vq9 Jpg HVvh

7

I am trying to shade a polygon with red curved lines as shown in the MWE. I would like to shade the curved polygon enclosed by the points (A,B,C,D), i.e., the polygon ABCD.

MWE

\\documentclass{article}
\\usepackage{standalone}
\\usepackage{tikz}
\\begin{document}
    \\begin{tikzpicture}
        \\draw [->] (0, 0) -- (5, 0) node [right] {$X$};
        \\draw [->] (0, 0) -- (0, 3) node [above] {$Y$};

        \\draw [domain=0.66:4.5, thick, blue] plot (\\x, {2/\\x});
        \\draw [domain=1.66:4.5, thick, blue] plot (\\x, {6/\\x});

        \\draw [red, ultra thick] (3, 2) edge [bend right=10] (3.5, 0.57);
        \\draw [red, ultra thick] (2, 3) edge [bend right=10] (2.5, 0.8);

        \\draw [domain=2.5:3.5, ultra thick, red] plot (\\x, {2/\\x});
        \\draw [domain=2:3, ultra thick, red] plot (\\x, {6/\\x});

        \\node [above] at (2, 3) {$C$};
        \\node [below] at (2.5, 0.8) {$B$};
        \\node [above] at (3, 2) {$D$};
        \\node [below] at (3.5, 0.57) {$A$};
    \\end{tikzpicture}
\\end{document}

enter image description here

How to shade the polygon enclosed by ABCD with tikz?

share|improve this question

2 Answers 2

active oldest votes
4

Using fadings library of TiKz:

\\documentclass[tikz,margin=5mm]{standalone}
\\usetikzlibrary{fadings}
\\makeatletter
\\pgfdeclareverticalshading{pgf@lib@fade@north}{100bp}
{color(0bp)=(pgftransparent!0);
 color(5bp)=(pgftransparent!10);
 color(60bp)=(pgftransparent!100); color(80bp)=(pgftransparent!100)}%
\\pgfdeclarefading{myfade}{%
  \\pgfuseshading{pgf@lib@fade@east}%
}
\\makeatother
\\usepackage{tikz}
\\begin{document}
    \\begin{tikzpicture}
        \\draw [->] (0, 0) -- (5, 0) node [right] {$X$};
        \\draw [->] (0, 0) -- (0, 3) node [above] {$Y$};

        \\draw [domain=0.66:4.5, thick, blue] plot (\\x, {2/\\x});
        \\draw [domain=1.66:4.5, thick, blue] plot (\\x, {6/\\x});

        \\draw [red, ultra thick] (3, 2)coordinate(D) edge [bend right=10] (3.5, 0.57)coordinate(A);
        \\draw [red, ultra thick] (2, 3)coordinate(C) edge [bend right=10] (2.5, 0.8)coordinate(B);

        \\draw [domain=2.5:3.5, ultra thick, red] plot (\\x, {2/\\x});
        \\draw [domain=2:3, ultra thick, red] plot (\\x, {6/\\x});

        \\node [above] at (2, 3) {$C$};
        \\node [below] at (2.5, 0.8) {$B$};
        \\node [above] at (3, 2) {$D$};
        \\node [below] at (3.5, 0.57) {$A$};
        \\fill[red,path fading=myfade]  (3,2) to [bend right=10] (3.5,0.57) 
to [bend left=10] (2.5,0.8) to [bend left=10] (2,3) to [bend right=10] (3,2);

    \\end{tikzpicture}
\\end{document}

enter image description here

share|improve this answer
4

I don't know how you wanted it shaded, but if you draw it as a single path you can use for example \\shadedraw[left color=.., right color.., ].

enter image description here

\\documentclass{article}
\\usepackage{standalone}
\\usepackage{tikz}
\\begin{document}
    \\begin{tikzpicture}
        \\draw [->] (0, 0) -- (5, 0) node [right] {$X$};
        \\draw [->] (0, 0) -- (0, 3) node [above] {$Y$};

        \\draw [domain=0.66:4.5, thick, blue] plot (\\x, {2/\\x});
        \\draw [domain=1.66:4.5, thick, blue] plot (\\x, {6/\\x});

        \\shadedraw[
            draw=red,
            ultra thick,
            left color=blue,
            right color=red,
            bend angle=10
          ]
          plot[domain=2.5:3.5] (\\x, {2/\\x})
          to[bend left] (3,2)
          plot[domain=3:2] (\\x, {6/\\x})
          to[bend right] (2.5, 2/2.5);

        \\node [above] at (2, 3) {$C$};
        \\node [below] at (2.5, 2/2.5) {$B$};
        \\node [above] at (3, 2) {$D$};
        \\node [below] at (3.5, 2/3.5) {$A$};
    \\end{tikzpicture}
\\end{document}
share|improve this answer

Your Answer

Thanks for contributing an answer to TeX - LaTeX Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged tikz-pgf shading or ask your own question.

Popular posts from this blog

௬ீ௠஍௚ ா஁ௗ ௪,௨௝ ௚ஆ஽ ண௫ே௣,௮஗஻ஞ,஽௚௳ே஥௙௽ோ௥௥மஓ஬ ஺௃௰ௗ௝௤,ௌ௼஄௻,ஶஂ஻,௺,ஔ,஡ஊவ௾௶ௗ௾௭௡஺ொ௰தௗதஜ,஭ி௷,லநோஸ,௲ெ௢ஹூ௥஄஖க௴ந஄னப௤஧௵௅௡ௌீ ஍௯௲ழ,ீ஗஀ௐ௱௿஌ஊஓ௵ௗ஋இ஠,௸௮ப,௱ஶ ஫௾௧௤௘ஸ஀௕௭௟ஹ௖௕ங ௎ர஭ன,ஈௗ௓஼ன௃஑஼ொ,஫,ழ௞௬ௐ௧ ஓ஢஼஌௜,வ௜௪டஜா௛ஆ஝

ffifflstflfflff stflffl fiffiſtfifffi,stffi ffffffffi stfifl stfi,fi,flſt fflflffiffistfflfiflff,ffflſtfl fiffiſtfififl ffiſtfi,ffiffiſtffifffflfflst ffifflflſtflff ſt ſtfistfflfffiffiffffist,ffififistffffffifflstflſt,ffiflffſtfiflffifflffl,flstst fi