# Fill the region bounded by two path in TikZ

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}


Namely, I want something like this:

• You should know to make your code compilable!! Dec 9, 2020 at 16:31

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{intersections}% <- not needed for the below code
\begin{document}
\begin{tikzpicture}[scale=1.7]
\begin{scope}
\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}


• Hmmh, just realize that the \clip strategy is the same as in hpekristiansen's answer. The only difference is that I fill first so that the line width stays intact.
– user230294
Dec 9, 2020 at 16:29
• Your method is better. I just did it quick without a scope to keep it simple. Dec 9, 2020 at 16:33
• I like |- cycle - I will have to keep that in mind. Dec 9, 2020 at 16:36
• @hpekristiansen One can also work with layers and so on. What is "better" depends on the context, which we do not know.
– user230294
Dec 9, 2020 at 16:36

\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}


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