2

The image below shows $A\cup C$.

union of sets

How could I plot the inverse, that is how would one fill the part of B not in A or C $B - (A\cup C)$, and leave A and C with no fill?

In case it's helpful, here is the code for making the picture shown:

\begin{tikzpicture}
  \filldraw[fill=lightgray] (0, 0) circle (1) {};
  \filldraw[fill=lightgray] (3.2, 0) circle (1) {};
  \draw (1.6, 0) circle (1) {};
  \node at (0, 0) {A};
  \node at (1.6, 0) {B};
  \node at (3.2, 0) {C};
\end{tikzpicture}
Sandy G
  • 42,558
ramzeek
  • 197
  • 6

3 Answers3

4

The inconvenient of filling A and C in white is that if you have a couloured background, it will be bad looking.

To avoid that and keep A and C transparent, you can use even odd rule and \clip:

even odd rule and clip

\documentclass[tikz,border=3.14mm]{standalone}

\begin{document} \begin{tikzpicture} \def\A{(0, 0) circle (1)} \def\B{(1.6, 0) circle (1)} \def\C{(3.2, 0) circle (1)}

    \begin{scope}
        \clip \B;
        \fill[lightgray,even odd rule] \A \B \C;
    \end{scope}

    \draw \A node {A} \B node {B} \C node {C};
\end{tikzpicture}

\end{document}

SebGlav
  • 19,186
1

Solution: fill the circles with B first and at the back, and A and C on top with white fill, then draw a circle for B on top to get its edges:

\begin{tikzpicture}
  \filldraw[fill=lightgray] (0, 0) circle (1) {};
  \filldraw[fill=lightgray] (3.2, 0) circle (1) {};
  \draw (1.6, 0) circle (1) {};
  \node at (0, 0) {A};
  \node at (1.6, 0) {B};
  \node at (3.2, 0) {C};

\filldraw[fill=lightgray] (8.6, 0) circle (1) {}; \filldraw[fill=white] (7, 0) circle (1) {}; \filldraw[fill=white] (10.2, 0) circle (1) {}; \draw (8.6, 0) circle (1) {}; \node at (7, 0) {A}; \node at (8.6, 0) {B}; \node at (10.2, 0) {C}; \end{tikzpicture}

union and difference

ramzeek
  • 197
  • 6
0

Here are some code of the cheap and nice way of @Sandy G (deleted! don't know why ^^)

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\pagecolor{yellow!50}
\begin{document}
\begin{tikzpicture}
\def\a{1.6} 
\fill[cyan!50] (\a,0) circle(1);
\draw[fill=white] (0,0) circle(1) (2*\a,0) circle(1);
\draw (\a,0) circle(1);
\path (0,0) node {$A$} (\a,0) node {$B$} (2*\a,0) node {$C$};
\end{tikzpicture}
\end{document}

and a translation to Asymptote

enter image description here

// http://asymptote.ualberta.ca/
unitsize(1cm);
real a=1.6;
path p=unitcircle;

fill(shift(a,0)p,magenta+white); filldraw(p^^shift(2a,0)p,white); draw(shift(a,0)*p);

label("$A$"); label("$B$",(a,0)); label("$C$",(2a,0));

shipout(bbox(5mm,Fill(yellow+white)));

Black Mild
  • 17,569