Graphics, Figures & TablesVenn Diagrams and Intersection Points

Information and discussion about graphics, figures & tables in LaTeX documents.
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Venn Diagrams and Intersection Points

Post by asmithb »

Dear Community,

I want to graph some Venn diagrams and highlight some intersection points, as shown on this website: https://verfassungsblog.de/veto-players ... -part-1-2/

I have added the picture of the website I am interested in. I want to highlight point SQ and the point where A and B intersect. However, I only find codes to highlight the intersection areas (but not the points themselves) and to magnify the intersection points (though I am not interested in magnifying such points).

Thank you very much for your support
Attachments
VPs.png
VPs.png (118.38 KiB) Viewed 6099 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Venn Diagrams and Intersection Points

Post by Bartman »

If you use tikz for the drawing, the intersection points can be calculated. You can use the assigned names or choose them yourself.
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Venn Diagrams and Intersection Points

Post by asmithb »

Could you please help me? So far I have just made the following Venn diagram and labeled the point SQ:

Code: Select all

\documentclass{article}
\usepackage{tikz}

\RequirePackage{xkeyval} 
\RequirePackage{tikz}
\RequirePackage{etoolbox}

\usetikzlibrary{shapes,backgrounds, intersections}

\begin{document}

\begin{tikzpicture}

\begin{scope} [fill opacity = .4]

    \draw (-5,5) rectangle (5,-6);

    \draw[fill=green, draw = black] (-1.5,1) circle (3);
    \draw[fill=blue, draw = black] (1.5,1) circle (3);
    \draw[fill=red, draw = black] (0,-2) circle (3);
    
\begin{scope}
  \clip \firstcircle;
  \clip \secondcircle;
  \draw[fill=white];
\end{scope}    
 
    \node at (-4,5.2) {\LARGE\textbf{X}};
    \node at (-3,4) {\LARGE\textbf{A}};
    \node at (3,4) {\LARGE\textbf{B}};
    \node at (-3,-4) {\LARGE\textbf{C}};
    \node at (0,0) {\LARGE\textbf{0}};
       \node at (0,-1.5) {\small\textbf{SQ}};
\end{scope}

\draw[help lines](-5,5) grid (5,-6);    

\end{tikzpicture}

\end{document}]
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Venn Diagrams and Intersection Points

Post by rais »

Your code errs out (neither \firstcircle nor \secondcircle is defined).
Perhaps something like this?

Code: Select all

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}

\begin{scope} [fill opacity = .4]

\draw (-5,5) rectangle (5,-6);
% name the paths:
\path[name path=A, draw, fill=green] (-1.5,1) circle (3) node(NA){};
\path[name path=B, draw, fill=blue] (1.5,1) circle (3) node(NB){};
\path[name path=C, draw, fill=red] (0,-2) circle (3) node(NC){};
\begin{scope}[fill opacity=1]% punch out the intersecting area of cicles A and B:
\clip (NB) circle (2.99297);% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
\fill[white] (NA) circle (2.99297);% same here for circle A
\end{scope}% end the scope to be able to draw something outside its clip area

% get the intersection points between circles A and B:
\path[name intersections={of=A and B}];
\begin{scope}[fill opacity=1]% put some solid dots at the intersecting points:
\fill (intersection-1) circle (3pt) node[above]{$y$}; 
\fill (intersection-2) circle (3pt) node[below=3pt]{SQ};
\end{scope}

\node at (-4,5.2) {\LARGE\textbf{X}};
\node at (-3,4) {\LARGE\textbf{A}};
\node at (3,4) {\LARGE\textbf{B}};
\node at (-3,-4) {\LARGE\textbf{C}};
\node at (0,0) {\LARGE\textbf{0}};
\node at (0,-1.5) {\small\textbf{SQ}};
\end{scope}

\draw[help lines](-5,5) grid (5,-6);

\end{tikzpicture}

\end{document}
BTW: you should refrain from using \RequirePackage inside your document. That's more suited for packages / classes. Besides, \usepackage is even less to type ;)

KR
Rainer
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Venn Diagrams and Intersection Points

Post by asmithb »

Thank you very much!

I have one more question. How could I highlight the intersect area (originally filled in white color) with oblique lines or with other styles (not filled entirely with a color)?

How could I draw the intersect of the 3 circles A, B and C, instead of just A and B (as was done in your code).
Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Venn Diagrams and Intersection Points

Post by Bartman »

Read chapter 62 "Pattern Library".

Use the \clip command also for the node named NC before the \fill command within the scope environment.
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Venn Diagrams and Intersection Points

Post by asmithb »

Thank you for your reply. I have 2 more questions. IIn the following code, I want to keep the circle B lines intact (and the inner side of the intersection filled in white not blue) but do not know how to do it. In addition, I want to point the intersects of A and C, but do not know how to do it. Could you help me?

Code: Select all

\begin{tikzpicture}
 
\begin{scope} [fill opacity = .4]
 
\draw (-5,5) rectangle (5,-6);
% name the paths:
\path[name path=A, draw, fill=green] (-1.5,1) circle (3) node(NA){};
\path[name path=B, draw, fill=blue] (-2,1.5) circle (1.4) node(NB){};
\path[name path=C, draw, fill=red] (0,-2) circle (3) node(NC){};
\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:

\clip  (NA) circle (3);
%\clip  (NB) circle (1.4);
\clip  (NC) circle (3);


% half the line width smaller than the circle's radius
% to keep the circle's line (B) intact.
% (= 3cm - 0.2pt * 2.54cm/in / 72.27pt/in)
%\fill[white] (NA) circle (3);
\fill[white] (NC) circle (3)% same here for circle A
\end{scope}% end the scope to be able to draw something outside its clip area
 
% get the intersection points between circles A and B:
\path[name intersections={of=A and B}];
\begin{scope}[fill opacity=1]% put some solid dots at the intersecting points:

\fill (intersection-3) circle (3pt) node[above=3pt]{SQ};
\end{scope}
 
\node at (-4,5.2) {\LARGE\textbf{X}};
\node at (-3,4) {\LARGE\textbf{A}};
\node at (-2,1.5) {\LARGE\textbf{B}};
\node at (-3,-4) {\LARGE\textbf{C}};
\node at (0,0) {\LARGE\textbf{0}};

\end{scope}
 
\draw[help lines](-5,5) grid (5,-6);
 
\end{tikzpicture}
Last edited by Stefan Kottwitz on Mon Mar 08, 2021 4:47 pm, edited 1 time in total.
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Venn Diagrams and Intersection Points

Post by rais »

asmithb wrote:IIn the following code, I want to keep the circle B lines intact (and the inner side of the intersection filled in white not blue) but do not know how to do it.
You can do the same thing with circles B and C like I did with circles A and B.
Since I left the calculation for getting radius - half the line width as a comment in the code using the original 3 cm for the radius, it doesn't need a druid to replace 3 cm with 1.4 cm, does it?
On the other hand, you'd have to adapt the calculated values if you change the line width, e.g., to `thick' (0.8 pt). It may be more convenient if the line width could be disregarded completely---which it can, if the circles are drawn after all the clippings are done.
asmithb wrote:In addition, I want to point the intersects of A and C, but do not know how to do it.
Well, instead of or additionally to name intersections={of=A and B} you use name intersections={of=A and C}.
In the code below I used the name option to get AB-* (intersecting points A and B), AC-* (intersecting points A and C), and BC-* (intersecting points B and C).
asmithb wrote: \fill (intersection-3) circle (3pt) node[above=3pt]{SQ};
with circles you only get a third intersecting point if both circles have the same size and origin.

Code: Select all

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
\def\rA{3}% radius circle A
\def\rB{1.4}% radius circle B
\def\rC{3}% radius circle C
\begin{scope} [fill opacity = .4]

\draw (-5,5) rectangle (5,-6);
% name the paths:
\path[name path=A, fill=green] (-1.5,1) circle (\rA) node(NA){};
\path[name path=B, fill=blue] (-2,1.5) circle (\rB) node(NB){};
\path[name path=C, fill=red] (0,-2) circle (\rC) node(NC){};

\begin{scope}[fill opacity=1]% punch out the intersecting area of circles A and C:
\clip (NA) circle (\rA);
%\clip (NB) circle (\rB);
%\clip (NC) circle (\rC);
\fill[white] (NC) circle (\rC);%
\end{scope}% end the scope to be able to draw something outside its clip area

\begin{scope}[fill opacity=1]% intersecting area C / B:
\clip (NC) circle (\rC);
\fill[cyan] (NB) circle (\rB);
\end{scope}% same here

% get the intersection points between circles A and B:
\path[name intersections={of=A and B, name=AB}];
% get the intersection points between circles A and C:
\path[name intersections={of=A and C, name=AC}];
% get the intersection points between circles B and C:
\path[name intersections={of=B and C, name=BC}];
\begin{scope}[fill opacity=1]
%(re-)draw the circles:
\draw (NA) circle(\rA) (NB) circle (\rB) (NC) circle(\rC);
% put some solid dots at the intersecting points:
% since circle B does not intersect with circle A, there won't be any intersecting points (AB-*)
\fill (AC-1) circle (3pt) node[left=3pt]{SQ};
\fill (AC-2) circle (3pt) node[right=3pt]{SQ$'$};
\fill (BC-1) circle (3pt) +(0,-0.3) node[right]{SQ$''$};
\fill (BC-2) circle (3pt) +(0,-0.3) node[right]{SQ$'''$};
\end{scope}

\node at (-4,5.2) {\LARGE\textbf{X}};
\node at (-3,4) {\LARGE\textbf{A}};
\node at (-2,1.5) {\LARGE\textbf{B}};
\node at (-3,-4) {\LARGE\textbf{C}};
\node at (0,0) {\LARGE\textbf{0}};

\end{scope}

\draw[help lines](-5,5) grid (5,-6);

\end{tikzpicture}

\end{document}
KR
Rainer
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Venn Diagrams and Intersection Points

Post by asmithb »

Thank you very much!
asmithb
Posts: 24
Joined: Tue Feb 23, 2021 12:04 pm

Venn Diagrams and Intersection Points

Post by asmithb »

Could you help me create a legend such as the one in the first image I shared (taken from the website)?
Post Reply