又一天,又一个问题!这次我不明白为什么填充后,tikz 会留下这样的空白
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\coordinate (O) at (0,0);
\coordinate (I) at (12,0);
\coordinate (C1) at (4,0);
\coordinate (C2) at (7,0);
\draw ($ (O)+(-1,0) $) -- ($ (I)+(1,0) $);%asse ottico
\draw [very thick] (C1)++(75:-3) node (A1) {A1} arc (75:-75:-3) node (B1)
{B1};
\draw [very thick] (C2)++(75:3) node (A2) {A2} arc (75:-75:3) node (B2) {B2};
\begin{scope}
\clip (C1)++(75:-3) arc (75:-75:-3) -- (A2) -- (C2)++(75:3) arc (75:-75:3) --
(A1);
\filldraw [color=lightgray, opacity=0.6] (-10,-10) rectangle (20,10);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
您甚至不需要clip
在这里。问题是您++
在路径中使用了增量。您可以对第一个坐标执行此操作,但如果对其他坐标执行此操作,则路径会出现“跳跃”。然而,当您正在加载时calc
,您可以这样做
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\coordinate (O) at (0,0);
\coordinate (I) at (12,0);
\coordinate (C1) at (4,0);
\coordinate (C2) at (7,0);
\draw ($ (O)+(-1,0) $) -- ($ (I)+(1,0) $);%asse ottico
\draw [very thick] (C1)++(75:-3) node (A1) {A1} arc (75:-75:-3) node (B1)
{B1};
\draw [very thick] (C2)++(75:3) node (A2) {A2} arc (75:-75:3) node (B2) {B2};
\fill[color=lightgray, opacity=0.6](C1)++(75:-3) arc (75:-75:-3)
-- ($(C2)+(75:3)$) arc (75:-75:3) -- cycle ;
\end{tikzpicture}
\end{document}
但是,由于您已经有命名节点,因此可以将其简化为
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc,backgrounds}
\begin{document}
\begin{tikzpicture}[scale=0.7]
\coordinate (O) at (0,0);
\coordinate (I) at (12,0);
\coordinate (C1) at (4,0);
\coordinate (C2) at (7,0);
\draw ($ (O)+(-1,0) $) -- ($ (I)+(1,0) $);%asse ottico
\draw [very thick] (C1)++(75:-3) node (A1) {A1} arc (75:-75:-3) node (B1)
{B1};
\draw [very thick] (C2)++(75:3) node (A2) {A2} arc (75:-75:3) node (B2) {B2};
\begin{scope}[on background layer]
\fill[color=lightgray, opacity=0.6](A1.center) arc (75:-75:-3) --
(A2.center) arc (75:-75:3) -- cycle ;
\end{scope}
\end{tikzpicture}
\end{document}
这里我也把填充放上了background layer
。