查看了 PGF 手册后,我认为上面的图片可能是使用命令\clip
和来绘制的\usetikzlibrary{patterns}
。
我有一个更简单的例子如下:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{scope}
\clip[draw](0,0) circle(1);
\fill[pattern=north east lines](1.5,0) circle(1);
\end{scope}
\draw (1.5,0) circle(1);
\end{tikzpicture}
\end{figure}
\end{document}
并生成以下图片:
但是,解决原始问题对我来说似乎有点困难,因为我不知道如何\clip
正确使用。您的提示将不胜感激。谢谢!
答案1
下部(垂直线)比较棘手,我不得不作弊。其余部分使用 和 就相当简单\clip
了even odd rule
。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{patterns,intersections}
\begin{document}
\begin{tikzpicture}
\def\A{(-.75,0) circle (2)}
\def\B{(.75,0) circle (2)}
\def\C{(0,0) to[out=-150,in=180,looseness=2] (0,-3.5) to[out=0,in=-30,looseness=2] (0,0) -- cycle}
\path [name path=A] \A;
\path [name path=B] \B;
\path [name path=C] \C;
\path [name intersections={of=A and B,by={p1,p2}}];
\path [name intersections={of=A and C,by={q1,q2}}];
\path [name intersections={of=B and C,by={r1,r2}}];
\begin{scope}
\clip (q1) -- (p2) -- (r2) --++ (.5,0) |-++ (-4.5,-2) |- (q1);
\fill[even odd rule,pattern=vertical lines] \A \B \C ;
\end{scope}
\begin{scope}
\clip \A;
\clip \B;
\fill[pattern=horizontal lines] \C;
\end{scope}
\begin{scope}
\clip \C;
\fill[even odd rule,pattern=north east lines] \A \B;
\end{scope}
\draw \A \B \C;
\end{tikzpicture}
\end{document}
可能有人会想出更好的解决方案,我期待从中学习。
答案2
在等待TikZ
,或...时
考虑以下因素渐近线代码:
size(7cm);
import patterns;
// Two circles
path c1=circle((-0.35,0),1);
path c2=circle((0.35,0),1);
// Two arrows
arrow("$E_1$",relpoint(c1,0.3),dir(135),align=0.3Relative(S),NoMargin);
arrow("$E_2$",relpoint(c2,0.24),dir(40),align=0.3Relative(S),NoMargin);
// free path
path g1=(0,0){dir(-145)}..tension 3 and 2 ..(-1,-1.25)..{dir(0)}(0,-1.6);
path g2=reflect((0,0),(0,1))*g1;
path combinedpaths=g1&reverse(g2)&cycle;
// patterns
add("patternA",hatch(2mm,dir(0)));
add("patternB",hatch(1mm,dir(45)));
add("patternC",hatch(2mm,dir(90)));
// all needed paths
picture pic1,pic2,pic3,pic4;
fill(pic1,c1,pattern("patternA"));
clip(pic1,c2);
clip(pic1,combinedpaths);
add(pic1);
fill(pic2,c1,pattern("patternB"));
unfill(pic2,c2);
clip(pic2,combinedpaths);
add(pic2);
fill(pic3,c2,pattern("patternB"));
unfill(pic3,c1);
clip(pic3,combinedpaths);
add(pic3);
fill(pic4,combinedpaths,pattern("patternC"));
unfill(pic4,c1);
unfill(pic4,c2);
add(pic4);
draw(c1^^c2);
draw(combinedpaths);
答案3
另一个 Ti钾Z 方法。与 SebGlav 的方法 (+1) 没什么不同,但改变了预定义路径。我不使用交叉点,但even odd rule
我不得不承认我使用了一个我不太满意的技巧:你可以看到我画了垂直线,然后我覆盖了其中的一部分。正如 SebGlav 所说,也许有更好的解决方案。
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns}
\newcommand{\circlesint}{(270:{0.5*sqrt(3)}) arc (-60:60:1) arc (120: 240:1)}
\newcommand{\circlesext}{(270:{0.5*sqrt(3)}) arc (300:60:1) arc (120:-120:1)}
\newcommand{\guitarpick}{[rounded corners](0,0) to[out=-40,in=120] (-50:1.5) to[out=270,in=270] (230:1.5) to[out=60,in=220] (0,0)}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,scale=2]
% vertical lines
\path[pattern=vertical lines] \guitarpick;
\fill[white] \circlesext; % covered part (a trick)
% horizontal lines
\begin{scope}
\clip\circlesint -- cycle;
\fill[pattern=horizontal lines] \guitarpick;
\end{scope}
% north east lines
\begin{scope}
\clip \guitarpick;
\fill[pattern=north east lines] \circlesint \circlesext;
\end{scope}
% cricles and guitar pick
\draw \circlesext \circlesint \guitarpick;
% labels
\foreach\i in{1,2}
\draw[-latex] (2*\i-3,1.25) node[above] {$E_\i$} -- (\i-1.5,1);
\end{tikzpicture}
\end{document}
答案4
TikZ 的另一种解决方案......
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, patterns}
\newcommand{\cirin}{($(0.5,0)+(120:1)$)
arc[start angle=120, end angle=240, radius=1]
arc[start angle=-60, end angle=60, radius=1] -- cycle;}
\newcommand{\cirout}{($(0.5,0)+(-120:1)$)
arc[start angle=-120, end angle=120, radius=1]
arc[start angle=60, end angle=-60, radius=1]
arc[start angle=300, end angle=60, radius=1]
arc[start angle=120, end angle=240, radius=1] -- cycle;}
\newcommand{\cirbottom}{(1.5,0)
arc[start angle=0, end angle=-120, radius=1]
arc[start angle=300, end angle=180, radius=1] -- ++(0,-2) -- ++(3,0) -- cycle;}
\newcommand{\curv}{(0,0) .. controls +(220:0.5) and +(180:2) ..
(0,-1.6) .. controls +(0:2) and +(320:0.5) .. (0,0) -- cycle;}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip\cirin
\path[pattern=horizontal lines] \curv
\end{scope}
\begin{scope}
\clip[draw]\cirout
\path[pattern=north east lines] \curv
\end{scope}
\begin{scope}
\clip[draw]\curv
\path[pattern=vertical lines] \cirbottom
\end{scope}
\end{tikzpicture}
\end{document}
更新
通过剪辑和交叉段重组找到新的答案。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\newcommand{\curv}[1]{\path[#1] (0,0) .. controls +(220:0.5) and +(180:2) ..
(0,-1.6) .. controls +(0:2) and +(320:0.5) .. (0,0) -- cycle;}
\begin{document}
\begin{tikzpicture}
\path[name path=A] (-1.5,0) arc[start angle=-180, end angle=0, radius=1];
\path[name path=B] (-0.5,0) arc[start angle=-180, end angle=0, radius=1];
\begin{scope}
\clip[intersection segments={of=A and B, sequence={R1 -- L2}}];
\curv{pattern=horizontal lines}
\end{scope}
\begin{scope}
\clip[intersection segments={of=A and B, sequence={L1 -- R1[reverse]}}];
\curv{pattern=north west lines}
\end{scope}
\begin{scope}
\clip[intersection segments={of=A and B, sequence={L2[reverse] -- R2}}];
\curv{pattern=north east lines}
\end{scope}
\begin{scope}
\clip[intersection segments={of=A and B, sequence={L1 -- R2}}] |- ++(-3,-2) -- cycle;
\curv{pattern=vertical lines}
\end{scope}
\draw (-0.5,0) circle[radius=1] (0.5,0) circle[radius=1];
\curv{draw}
\end{tikzpicture}
\end{document}