在 tikz 中绘制重叠的复杂性类别

在 tikz 中绘制重叠的复杂性类别

我正在尝试在 tikz 中创建复杂性类别的图示。类似这样:在此处输入图片描述

有人能帮我吗?我遇到的问题是如何绘制椭圆,使它们水平居中并相互重叠。

答案1

这是一个宏\cclasses,它将为给定的一组类绘制图像:

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

在此处输入图片描述

\cclasses{PSPACE,NP,P}

在此处输入图片描述

在下面的代码中,\xcontrol\ycontrol可以改变以调整椭圆的偏心率。可以通过调整 的公式来调整阴影步骤\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}

答案2

绘制嵌套椭圆并不难。添加标签留作练习。

\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}

在此处输入图片描述

答案3

有些事要开始。

\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}

在此处输入图片描述

相关内容