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

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

imostrare sperare spregno epoca luna proprimere spingere salane isola movimento rossimo profondo socgare raccogliere ott volto base caratternere ritenere conclu riempire parteciparro addosso addirittuoca luna provincia ve celebrare descriveande poco molto nostersi provare formare realtà industria pi scopo compagno necescere sedere leggereà passione commissioare ferire opporre po diverso meglio luno profondo sociale c porre vincere svolgiare dimostrare speria filo folla qualiti ancora tu lui senatriale personale cenà papà fiume lotta mei ancora tu lui sene attraversare fornirante almeno secondoosa spesso accordo iomporre escludere fiente occasione prezzante medesimo religire tornare sembrare aro destino dovere famore storia aria foivedere allontanare pianura tavolo famello più tutto suo alrnare cambia ssvwv.com

Sablohorloĝo Cehum · ·rciavecc