[Tex/LaTex] How to fill a region in tikz

filltikz-pgf

I did the following drawing in Tikz:

MWE:

\documentclass[border=5pt,tikz] {standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[thick] (-0.25,0) circle (2);
        \draw[thick] (0.25,0) circle (2);
        \draw (0.25,0) node[above] {$w$};
        \draw (-0.25,0) node[above] {$z$};
        \draw (0.25,0) node {$\bullet$};
        \draw (-0.25,0) node {$\bullet$};
        \draw (2,0) node {$B$};
        \draw (-2,0) node {$A$};
    \end{tikzpicture}
\end{document}

I would like to fill the A and B regions with a light gray. I know how to fill a whole circle but I don't know how to fill such a specific region. What is the best way to do that?

Best Answer

In addition to @current_user's response, we can use the even odd rule here to color the part that is inside a path.

The path traced here is the succession of the two center circles z and w:

\filldraw[thick,fill=green!50,even odd rule] (-0.25,0) circle (2) (0.25,0) circle (2);

To explain this rule, I added two arrows, one of origin z and end z', the other being Bb'. These arrows indicate whether their origin z and B are inside or outside the path traced. They are always traced to infinity.

Starting from the z point, the arrow meets the path twice, two times is even, so the z point is outside the path and therefore the area in which it is located is not colored.

Starting from point B, the arrow meets the path once, one is odd, so B is inside the path and is therefore colored.

even-odd-rule

\documentclass[border=5mm,tikz] {standalone}
\begin{document}
    \begin{tikzpicture}
        \filldraw[thick,fill=green!50,even odd rule] (-0.25,0) circle (2) (0.25,0) circle (2);
        \draw (0.25,0) node[above] {$w$};
        \draw (-0.25,0) coordinate (z) node[above] {$z$};
        \draw (0.25,0) node {$\bullet$};
        \draw (-0.25,0) node {$\bullet$};
        \draw (2,0) node {$B$};
        \draw (-2,0) node {$A$};
        %drawing arrows to explain the even odd rule
        \coordinate(z') at (-2.5,.5);
        \draw[->](z)--(z')node[left]{z'};
        \coordinate (b) at (2,.25);
        \coordinate (b') at (2.5,1);
        \draw[->](b)node{$\bullet$}--(b')node[above right]{b'};
    \end{tikzpicture}
\end{document}

Translated with www.DeepL.com/Translator