我想使用 tikz 填充两个半圆之间的区域。以下是我尝试过但失败了的方法。
\documentclass[a4paper,12pt]{article}
\begin{tikzpicture}
\draw [-, ] (-3,0) --(-0.4,0);
\draw [-, ] (0.4,0) --(3,0);
\fill[gray!15] ( -3,-3) |- (-0.4,0) arc (-180:0:4mm)-- (3,0) -|
(3,-3);
\draw [blue,thick,domain=180:360] plot ({.4*cos(\x)}, {.4*sin(\x)});
\draw [blue,thick,domain=180:360] plot ({3*cos(\x)}, {3*sin(\x)});
\end{tikzpicture}
\end{document}
答案1
像这样?
\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [-] ( -3,0) -- (-0.4,0)
(0.4,0) -- (3,0);
\fill[gray!15] (-3,0) -- (-0.4,0) arc (-180:0: 4mm)
-- (3,0) arc (0:-180:30mm); % <-- changed
\draw [blue,thick,domain=180:360] plot ({.4*cos(\x)}, {.4*sin(\x)});
\draw [blue,thick,domain=180:360] plot ({ 3*cos(\x)}, { 3*sin(\x)});
\end{tikzpicture}
\end{document}
附录:考虑保罗·加博利在下面发表评论,您的 MWE 可以简化和改进,arc
而是使用绘制plot
函数:
\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [-] ( -3,0) -- (-0.4,0)
(0.4,0) -- (3,0);
\fill[gray!15] (-3,0) -- (-0.4,0) arc (-180:0: 4mm)
-- (3,0) arc (0:-180:30mm);
\draw[blue,thick] (.4,0) arc (0:-180: 4mm); % <-- changed
\draw[blue,thick] ( 3,0) arc (0:-180:30mm); % <-- changed
\end{tikzpicture}
\end{document}