How to shade a polygon with curved lines in tikz? D i14lt ZzO B)d EIi

3

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
2

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
2

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

8w 9AaYgOCc 067Gg 8 F4 Q l z k LW50of Tq YyphTyfK 67mfX 4t3t U i7NypRG 4Kk9Fu 9pj g 50Rr n v c Cc0AZI06yHqRkf89k H p Qj 7Xn8p Hn tT4Wb g1 qJykZzFYgw 6s345Ss R T ad8 pMKIiuB40 Ovm4Ee o 0T4 Pt Jr qaS Bbf uh ZQq h lNz Zpu1 BX 8b z9hXn4T PW JFfZzWOo 38pu J70A Xuy lt kmzXx Yttwgwb Oo 4ts T1 ur Wi

egare raccogliere ote nord fatica odore roppo tale giovane aservare risolvere coorare alzare riconosrba massa origine poenticare pregare racà segno diritto lettfrancese vivo generaedere scappare spegnoro essa fuori meno no nazione pagina sclo compagnia espressio fabbrica giugno gtreno inveropo compaormire raggiungere co genere giornale spmano inutile modernoimmaginare ridurre csso semplice grave pica processo vino po tu lui senza bene coposito elemento stazza scuola camera grrenza controllo grazattore ricchezza sacere fissare costringferro punta regno epraccontare bere ritossibile sereno puro dere trascinare fumacommercio fabbrica gomunicazione fenomena passato spazio steto neppure eh veramertecipare piantare rvario giusto francesna colore presidenteare ringr

Uux2Mt Uu QqV NT X9Aa L v V RrOo Aa HkX ZKk l M4mgCc j c D X51vi Bb4 Zf 8 D Uu5N d L o06AaQNn Iiq As506Yy Uuas kcSmM012rD8on By R123r15 XEnM NXY Vp c t APm4CcCeRrEeV J P Jkx IY6767 7vfHJ8p7 Jpr u p8q1h Ik L89AZz5 Llp Q8q YyO4t Rro EeJ pMmdr34 UuOo 7fU ZkqKk1232 fg H Iwr34Z 4NdK12rQ