TeX - LaTeX Asked on December 26, 2020
How to fill the region (with gray!50) bounded by two path in TikZ? I have tried many solutions, but they all don’t work.
begin{tikzpicture}[scale=1.7]
draw[semithick] (0,0) -- (2,0) -- (2,2) -- (0,2) -- cycle;
draw[name path=f, semithick] (1,1) circle (1);
draw[name path=g, semithick] (0,0) arc (270:360:2);
end{tikzpicture}
documentclass[tikz,border=3mm]{standalone}
usetikzlibrary{intersections}% <- not needed for the below code
begin{document}
begin{tikzpicture}[scale=1.7]
begin{scope}
clip (1,1) circle [radius=1];
fill[gray] (0,0) arc[start angle=270,end angle=360,radius=2] |- cycle;
end{scope}
draw[semithick] (0,0) rectangle (2,2);
draw[name path=f, semithick] (1,1) circle [radius=1];
draw[name path=g, semithick] (0,0) arc[start angle=270,end angle=360,radius=2];
end{tikzpicture}
end{document}
Correct answer by user230294 on December 26, 2020
clip
makes everything following only drawn inside the clip path.
documentclass[tikz, border=1cm]{standalone}
begin{document}
begin{tikzpicture}
draw (0,0) rectangle (2,2);
draw (0,0) arc (270:360:2);
draw[clip] (1,1) circle (1);
fill[gray!50] (0,0) arc (270:360:2) -- (2,0) -- cycle;
end{tikzpicture}
end{document}
Answered by hpekristiansen on December 26, 2020
An other way to do it, without the clip command, is to fill the region first, then draw the lines.
documentclass[tikz, border=1cm]{standalone}
usetikzlibrary{intersections}
begin{document}
begin{tikzpicture}[scale=1.7]
fill[gray!50] (1,1) circle (1); % gray circle
fill[white] (0,0) arc (270:360:2) -| cycle; % white sector over
draw[semithick] (0,0) -- (2,0) -- (2,2) -- (0,2) -- cycle;
draw[name path=f, semithick] (1,1) circle (1);
draw[name path=g, semithick] (0,0) arc (270:360:2);
end{tikzpicture}
end{document}
This gives the following
Answered by Alain Remillard on December 26, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP