
我正在使用 TikZ 套件來顯示一組複數,其中我想要的複數位於半徑為 2 的圓的外部,而半徑為 1 的圓不在集合中:
我想讓內圓變成白色,軸完全顯示,但我不知道如何做。我使用兩個帶有半透明填充物的圓圈。有沒有辦法只填充外部?相關代碼如下。
(這是我獲得大部分程式碼的地方:在複平面上畫一個圓。)
\begin{tikzpicture}
\begin{scope}[thick,font=\scriptsize][set layers]
\draw [->] (-4,0) -- (4,0) node [above left] {$\Re\{z\}$};
\draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
\iffalse% Single
\draw (1,-3pt) -- (1,3pt) node [above] {$1$};
\draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
\draw (-3pt,1) -- (3pt,1) node [right] {$i$};
\draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
\else% Multiple
\foreach \n in {-3,...,-1,1,2,...,3}{%
\draw (\n,-3pt) -- (\n,3pt) node [above] {$\n$};
\draw (-3pt,\n) -- (3pt,\n) node [right] {$\n i$};
}
\fi
\end{scope}
\draw[solid] (0,-1) circle (1);
\draw[solid] (0,-1) circle (2);
\path [draw=none,fill=gray, fill opacity = 0.1] (0,-1) circle (2);
\path [draw=none,fill=white, fill opacity = 0.7] (0,-1) circle (1);
\node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
\end{tikzpicture}
答案1
您可以使用不同的填滿規則,該規則稱為even odd rule
填入每個偶數閉合區域。
因此,如果您使用以下行而不是兩個不同的圓圈,您將獲得一個甜甜圈填充;
\path [draw=none,fill=gray, fill opacity = 0.1,even odd rule] (0,-1) circle (2) (0,-1) circle (1);
答案2
在這種特殊情況下,您可以簡單地更改繪製順序,即先繪製圓圈:
\documentclass[tikz]{standalone}
\usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}
\path [draw=none,fill=gray, fill opacity = 0.1] (0,-1) circle (2);
\path [draw=none,fill=white] (0,-1) circle (1);
\begin{scope}[thick,font=\scriptsize][set layers]
\draw [->] (-4,0) -- (4,0) node [above left] {$\Re\{z\}$};
\draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
\iffalse% Single
\draw (1,-3pt) -- (1,3pt) node [above] {$1$};
\draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
\draw (-3pt,1) -- (3pt,1) node [right] {$i$};
\draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
\else% Multiple
\foreach \n in {-3,...,-1,1,2,...,3}{%
\draw (\n,-3pt) -- (\n,3pt) node [above] {$\n$};
\draw (-3pt,\n) -- (3pt,\n) node [right] {$\n i$};
}
\fi
\end{scope}
\draw[solid] (0,-1) circle (1);
\draw[solid] (0,-1) circle (2);
% \path [draw=none,fill=gray, fill opacity = 0.1] (0,-1) circle (2);
% \path [draw=none,fill=white, fill opacity = 0.7] (0,-1) circle (1);
\node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
\end{tikzpicture}
\end{document}
答案3
使用「奇偶規則」:
\documentclass[tikz]{standalone}
\usepackage{amsfonts}
\begin{document}
\begin{tikzpicture}
\begin{scope}[thick,font=\scriptsize][set layers]
\draw [->] (-4,0) -- (4,0) node [above left] {$\Re\{z\}$};
\draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
\iffalse% Single
\draw (1,-3pt) -- (1,3pt) node [above] {$1$};
\draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
\draw (-3pt,1) -- (3pt,1) node [right] {$i$};
\draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
\else% Multiple
\foreach \n in {-3,...,-1,1,2,...,3}{%
\draw (\n,-3pt) -- (\n,3pt) node [above] {$\n$};
\draw (-3pt,\n) -- (3pt,\n) node [right] {$\n i$};
}
\fi
\end{scope}
\draw[solid] (0,-1) circle (1);
\draw[solid] (0,-1) circle (2);
\path [draw=none, fill=gray, even odd rule, fill opacity = 0.1] (0,-1) circle (2) (0,-1) circle (1);
\node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
\end{tikzpicture}
\end{document}
編輯
由於使用奇偶規則解決方案時,打擊速度更快(但我注意到,它沒有提供完整的 MWE),如果您希望填充內圓,但仍希望軸位於頂部,則可以使用以下解決方案。該解決方案使用backgrounds
庫來填充內圓在後面圖片的其餘部分,使軸保持在頂部。
\documentclass[tikz]{standalone}
\usepackage{amsfonts}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\begin{scope}[thick,font=\scriptsize][set layers]
\draw [->] (-4,0) -- (4,0) node [above left] {$\Re\{z\}$};
\draw [->] (0,-4) -- (0,4) node [below right] {$\Im\{z\}$};
\iffalse % Single
\draw (1,-3pt) -- (1,3pt) node [above] {$1$};
\draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
\draw (-3pt,1) -- (3pt,1) node [right] {$i$};
\draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
\else% Multiple
\foreach \n in {-3,...,-1,1,2,...,3}{%
\draw (\n,-3pt) -- (\n,3pt) node [above] {$\n$};
\draw (-3pt,\n) -- (3pt,\n) node [right] {$\n i$};
}
\fi
\end{scope}
\draw[solid] (0,-1) circle (1);
\draw[solid] (0,-1) circle (2);
\path [fill=gray, fill opacity = 0.1] (0,-1) circle (2);
\begin{scope}[on background layer]
\path [fill=white, fill opacity=.7] (0,-1) circle (1);
\end{scope}
\node [below right,black] at (1.2,1.2) {$A=\{z\in\mathbb{C}:1\leq|z-(-i)|\leq2\}$};
\end{tikzpicture}
\end{document}
答案4
使用 MetaPost(透過 LuaLaTeX)完成,可能會對它感興趣。
使用 Metafun 格式進行透明填充:
fill ring withcolor transparent(1, 0.1, \mpcolor{gray});
環本身是透過將其中一個圓附加到相反的另一個圓上來創建的:
ring = circle1 -- reverse circle2 -- cycle;
(當然,一種更簡單、更快捷的方法是填充最大的圓圈並取消填充最小的圓圈,但我發現創建此環形路徑並直接填充它很有趣。)
完整程式碼:
\documentclass[12pt]{standalone}
\usepackage{amssymb, xcolor}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
u = 1.5cm; xmax = 3.9 = ymax = -ymin = -xmin; len = 6bp;
path circle[], ring;
circle1 = fullcircle scaled 2u shifted (0, -u);
circle2 = fullcircle scaled 4u shifted (0, -u);
ring = circle1 -- reverse circle2 -- cycle;
labeloffset := 6bp;
beginfig(1);
for i = ceiling(xmin) upto floor(xmax):
draw (i*u, -0.5len) -- (i*u, 0.5len);
if i <> 0: label.top("$" & decimal i & "$", (i*u, 0)); fi
endfor
for j = ceiling(ymin) upto floor(ymax):
draw (-0.5len, j*u) -- (0.5len, j*u);
if j <> 0: label.rt("$" & decimal j & "i$", (0, j*u)); fi
endfor
drawarrow (xmin*u, 0) -- (xmax*u, 0); label.top("$\Re\{ z \}$", (xmax*u, 0));
drawarrow (0, ymin*u) -- (0, ymax*u); label.rt("$\Im\{ z \}$", (0, ymax*u));
fill ring withcolor transparent(1, 0.1, \mpcolor{gray});
for i = 1,2: draw circle[i]; endfor
label.urt("$A = \{z \in \mathbb{C}: 1 \leqslant |z-(-i)| \leqslant2 \}$",
point 1.5 of circle2);
endfig;
\end{mplibcode}
\end{document}