4

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?

5

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

4
\documentclass[border=5pt,tikz]{standalone}
\tikzstyle{io} = [fill=black,inner sep=2pt,circle]
\begin{document}
    \begin{tikzpicture}
        \begin{scope}
            \clip (.5,0) circle(2);
                \fill[gray!20] (.25,-5) rectangle (-5,5);
        \end{scope}
        \begin{scope}
            \clip (0,0) circle(2);
                \fill[gray!20] (.25,-5) rectangle (5,5);
        \end{scope}
        \draw (0,0) circle(2);
        \draw (.5,0) circle(2);
            \node[right] at (-2,0) {$A$};
            \node[left] at (2.5,0) {$B$};
        \node[io,label={$z$}] at (0,0) {};
        \node[io,label={$w$}] at (.5,0) {};
    \end{tikzpicture}
\end{document}

Screenshot

  • @Herbert: Thank you! That bug is really awkward … – current_user Sep 10 '18 at 18:32
  • I did not undestand how you did the second drawing – Gabriel Sep 10 '18 at 19:12

Your Answer

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 or ask your own question.