1

I am representing sets using ellipses and would like to draw the difference between two sets: B - A (blue area in the figure below).

Please consider the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}

\begin{document}

\begin{tikzpicture}

\def\A{(0,0) ellipse (2cm and 3cm)} \def\B{(2,0) ellipse (3cm and 2cm)}

\draw[red] \A; \draw[green] \B;

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

\end{tikzpicture} \end{document}

that produces:

set difference

However, I define the ellipses using nodes, because I need to assign names to them. Basically, my ellipses are defined as:

\node [draw,transform shape, fill=blue!5,draw=blue,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TP) at (1.2,2) {};

Basically, I use \node instead of the simpler ellipse path because I want to have that TP name.

If I try and plot the set difference using ellipses defined with \node instead of (0,0) ellipse (2cm and 3cm), the compilation fails.

I have two questions:

  • Q1) Can I give a name to ellipses defined as in the code above (i.e., without using node)?

  • Q2) How can I clip using a \node and get the same result as in the picture above?

There is a question similar to this, but I am not able to comprehend the answers (too complex): Clipping a path using a node.

This is the actual tikz picture I am using:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}

\begin{document} \begin{tikzpicture}[scale=3] % frame \node [draw, transform shape, rectangle, minimum width=5cm, minimum height=3cm, anchor=south west] (F) at (0,0) {}; \node [below left] at (F.north east) {$U$};

\node [draw,transform shape, fill=blue!5,draw=blue,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TP) at (1.2,2) {}; \node [right] at (TP.west) {$A$};

\node [draw,transform shape,fill=red!5,draw=red,line width=1pt,ellipse,minimum width=2cm,minimum height=1.5cm] (TN) at (3.8,1) {}; \node [left] at (TN.east) {$B$};

\node [draw,transform shape,fill=green!5,draw=green, fill opacity=0.5, line width=1pt,ellipse,minimum width=2.5cm,minimum height=2cm] (COV) at (2.3,1.2) {}; \node [below right] at (COV.west) {$C$};

\end{tikzpicture} \end{document}

enter image description here

Starting from that picture, I need to draw:

  • A
  • C - A

I defined the ellipses using \node because I needed their names for anchor points.

  • 1
    Please add a full MWE with the node-ellipses. What kind of clip do you need? Do you want to draw the ellipses, should their borders also be clipped? Is it only about the filling? For what do you need to name the ellipse? This “only” gives you a neat access to its border/anchors. If the normal clipping is easy enough, maybe just do both: Drawing, filling and clipping with path-ellipses and an invisible node-ellipse on top? – Qrrbrbirlbel May 26 '23 at 21:39
  • 1
    That said, you can use the spath3 library to save the path of a node and then reuse it later to clip. It also has an interface for combining to paths (one for each node). On the other hand. Maybe all you need is a reverse clip solution. – Qrrbrbirlbel May 26 '23 at 22:35

0 Answers0