在 Tikz 中填充圆环的中间

在 Tikz 中填充圆环的中间

我使用 Tikz 绘制了以下圆环:

\begin{tikzpicture}
\fill[blue] (7.5,0) ellipse (1 and .75);
\draw (7.5,0) ellipse (1 and .75);
\begin{scope}
  \clip (7.5,-.9) ellipse (1 and 1.25);
  \draw (7.5,1.1) ellipse (1 and 1.25);
\end{scope}
\begin{scope}
  \clip (7.5,1.1) ellipse (1 and 1.25);
  \draw (7.5,-1.1) ellipse (1 and 1.25);
\end{scope}
\end{tikzpicture}

我想将它的中间部分涂成白色,这样它看起来就像一个圆环。我该怎么做?

答案1

答案是有一些很小的变化并且没有额外的库:

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\fill[blue] (7.5,0) ellipse (1 and .75);
\draw (7.5,0) ellipse (1 and .75);
\begin{scope}
  \clip (7.5,-.9) ellipse (1 and 1.25);
  \draw(7.5,1.1) ellipse (1 and 1.25);
  \clip (7.5,1.1) ellipse (1 and 1.25);
  \draw (7.5,-1.1) ellipse (1 and 1.25);
  \fill[white] (7.5,-1.1) ellipse (1 and 1.25);
\end{scope}
\end{tikzpicture}
\end{document}

带有库的答案fillbetweewn (在许多其他情况下有用):

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\fill[blue] (7.5,0) ellipse (1 and .75);
\draw (7.5,0) ellipse (1 and .75);
\begin{scope}
  \clip (7.5,-.9) ellipse (1 and 1.25);
  \path[draw,name path= A](7.5,1.1) ellipse (1 and 1.25);
  \clip (7.5,1.1) ellipse (1 and 1.25);
  \path[draw,name path=B] (7.5,-1.1) ellipse (1 and 1.25);
\fill [white,
          intersection segments={
            of=A and B,
            sequence={A1--B1}
          }];
\end{scope}
\end{tikzpicture}
\end{document}

两个答案都输出:

在此处输入图片描述

答案2

even odd rule只有两条线。(我强烈建议不要将某些区域填满白色,因为如果您在任何背景上使用它,您会后悔的。)

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[fill=blue,even odd rule] (7.5,0) ellipse (1 and .75) 
 (7,0) arc(120:60:1 and 1.25) arc(-60:-120:1 and 1.25);
\draw (7,0) arc(-120:-130:1 and 1.25) (8,0) arc(-60:-50:1 and 1.25);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容