0

I'm trying to create an illustration of complexity classes in tikz. Something like this: enter image description here

Can someone help me with that? The part I'm having trouble with is drawing the ellipses so that they are horizontally centered and overlap each other.

1
  • Maybe start by centering all ellipses on the same point and only successively increasing the x and y radius of each ellipse. Once you got that, shift the center of each new ellipse a bit and that should give you the desired effect
    – Raven
    Apr 4, 2022 at 12:36

3 Answers 3

2

Here is a macro \cclasses that will draw your image for a given set of classes:

\cclasses{EXPSPACE,EXPTIME,PSPACE,NP,P,NL}

enter image description here

\cclasses{PSPACE,NP,P}

enter image description here

In the code below, \xcontrol and \ycontrol can be changed to adjust the eccentricity of the ellipses. Shading steps can be adjusted by tweaking the formula for \drk.

\documentclass{article}

\usepackage{tikz,amsmath,ifthen}

\newcommand{\xcontrol}{.4}
\newcommand{\ycontrol}{.1}
\newcommand{\mayeq}{\overset{?}{=}}
\newcommand{\cclasses}[1]{\begin{tikzpicture}
    \foreach \c[count=\n] in {#1}{\xdef\numclasses{\n}}
    \foreach \c[count=\n, evaluate=\n as \m using \numclasses-\n+1, evaluate=\n as \drk using 10+80*\n/\numclasses] in {#1}{
        \fill[gray!\drk] (0,\m/3) ellipse ({\xcontrol+.5*\m} and {\ycontrol+.5*\m});
        \ifthenelse{\n=1}{}{\node at (0,\m/3+\ycontrol+.5*\m){$\mayeq$};}
        \node[right,font={\sffamily}] at (0,{(\m/3+\ycontrol+.5*\m)-.45}){\c};}
    \draw ((0,\numclasses/3) ellipse ({\xcontrol+.5*\numclasses} and {\ycontrol+.5*\numclasses});
    \end{tikzpicture}}

\begin{document}

\cclasses{EXPSPACE,EXPTIME,PSPACE,NP,P,NL}

\end{document}
3

Drawing nested ellipses is not hard. Adding labels is left as an exercise.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \draw (0,60pt) ellipse (180pt and 120pt);
  \foreach \x in {60,50,...,10} {
    \fill[white!\x!black] (0,\x pt) ellipse ({3*\x pt} and {2*\x pt});
  }
\end{tikzpicture}
\end{document}

enter image description here

1
  • hypnotic image !
    – JeT
    Apr 4, 2022 at 18:47
2

Something to start.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{shapes.geometric, positioning}

\begin{document}
\begin{tikzpicture}[myellipse/.style 2 args={ellipse, fill=black!#1, label={[anchor=north, below=2.5mm]#2}}, font=\sffamily]

\node[myellipse={10}{EXPSPACE}, minimum width=12cm, minimum height=6cm, draw] (e1) {};
\node[myellipse={20}{EXPTIME}, minimum width=10cm, minimum height=5cm, above=2mm of e1.south] (e2) {};
\node[myellipse={30}{PSPACE}, minimum width=8cm, minimum height=4cm, above=2mm of e2.south] (e3) {};
\node[myellipse={40}{NP}, minimum width=6cm, minimum height=3cm, above=2mm of e3.south] (e4) {};
\node[myellipse={50}{P}, minimum width=4cm, minimum height=2cm, above=2mm of e4.south] (e5) {};
\node[myellipse={60}{}, minimum width=2cm, minimum height=1cm, above=2mm of e5.south] (e6) {NL};

\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .