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}
How to shade the polygon enclosed by ABCD with tikz?
tikz-pgf shading
add a comment |
2 Answers
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}
add a comment |
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.., ]
.
\\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}
add a comment |