I was able to modify Loop Space's code (the first answer found here: How to generate all possible Venn diagrams (with the case below) efficiently?) to draw a Venn diagram for four sets using ellipses. It appears to work for individual Venn diagrams, but when I try to use \allvendiagrams
, I get an error stating that the dimension is too large. I realize that there are 65,536 possible variations and it would not be practical to try and print a document containing all of them, but I would like to get the code to work if possible. My code is below:
\documentclass[border=3pt,tikz]{standalone}
%\url{https://tex.stackexchange.com/q/67395/86}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes.geometric}
\makeatletter
\def\venn@strip#1#2\venn@STOP{%
\def\venn@next{#1}%
\gdef\venn@rest{#2}%
}
\newcommand{\venn}[1]{%
\begin{tikzpicture}
\coordinate (A) at (1.6,0);
\coordinate (B) at (0.3,1);
\coordinate (C) at (-1.6,0);
\coordinate (D) at (-0.3,1);
\coordinate (S-SE) at (5,-4);
\coordinate (S-NW) at (-5,5);
\edef\venn@rest{#100000000}%
\foreach \i in {0,...,15} {
\begin{scope}[even odd rule]
\expandafter\venn@strip\venn@rest\venn@STOP
\ifnum\venn@next=1\relax
\pgfmathparse{Mod(\i,2) == 1 ? "(S-SE) rectangle (S-NW)" : ""}
\path[clip] \pgfmathresult (A) ellipse [x radius=3cm, y radius=1.5cm, rotate=50];
\pgfmathparse{Mod(floor(\i/2),2) == 1 ? "(S-SE) rectangle (S-NW)" : ""}
\path[clip] \pgfmathresult (B) ellipse [x radius=3cm, y radius=1.5cm, rotate=50];
\pgfmathparse{Mod(floor(\i/4),2) == 1 ? "(S-SE) rectangle (S-NW)" : ""}
\path[clip] \pgfmathresult (C) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50];
\pgfmathparse{Mod(floor(\i/8),2) == 1 ? "(S-SE) rectangle (S-NW)" : ""}
\path[clip] \pgfmathresult (D) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50];
\fill[rounded corners,gray!80] (S-SE) rectangle (S-NW);
\fi
\end{scope}
}
\draw[ultra thick] (A) ellipse [x radius=3cm, y radius=1.5cm, rotate=50];
\draw[ultra thick] (B) ellipse [x radius=3cm, y radius=1.5cm, rotate=50];
\draw[ultra thick] (C) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50];
\draw[ultra thick] (D) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50];
\draw[ultra thick,rounded corners] (S-SE) rectangle (S-NW);
\end{tikzpicture}
}
\makeatother
\newcommand{\allvendiagrams}{
% To generate the lot:
\foreach \j in {0,...,65535} {
\def\venncode{}
\foreach \k in {0,...,15} {
\pgfmathparse{Mod(floor(\j/2^\k),2) == 1 ? "\venncode1" : "\venncode0"}
\global\let\venncode=\pgfmathresult
}
\venn{\venncode}
}
}
\begin{document}
%\venn{0000000000000000} %0
%\venn{0000000000000001} %1
%\venn{0000000000000010} %2
%\venn{0000000000000011} %3
%\venn{0000000000000100} %4
%\venn{0000000000000101} %5
%\venn{0000000000000110} %6
%\venn{0000000000000111} %7
%\venn{0000000000001000} %8
%\venn{0000000010000000} %128
%\venn{0000000011111111} %255
%\venn{1111111111111111} %65535
\allvendiagrams
\end{document}
It should be noted that Overleaf gives the "Dimension too large" error but still produces the Venn diagrams. As expected, it times out when trying to generate all 65,536 variations; I'm currently running them 100 at a time. TexWorks gives the "Dimension too large" error and does not generate anything; I'd like to get the code to work in TexWorks if possible since I do not have a reliable internet connection at home.