我试图在一条线(从椭圆形)穿过圆圈时将其移除,但似乎无法使其工作:(
\begin{tikzpicture}
\shade[ball color = gray!100, opacity = 0.4] (0,0) circle (2cm);
\draw (0,0) circle (2cm);
\draw (-2,0) arc (180:360:2 and 0.6);
\draw[dashed] (2,0) arc (0:180:2 and 0.6);
\fill[fill=black] (0,0) circle (1pt);
\draw[dashed] (0,0 ) -- node[above]{$r$} (2,0);
\def \firstellipse {(-1.5,0) ellipse (2 and 4)}
\draw[dashed] \firstellipse
\end{tikzpicture}
因此,为了澄清起见,我想删除圆圈边界内的省略号部分!
答案1
那么你可以:
\clip
在椭圆前使用但是这需要额外的代码,或者更好......opacity = 0.4
从椭圆中删除并更改颜色命令(我假设您只是希望它更浅),例如从gray!100
1到。gray!10
另外,移动它
ellipse
以使其出现在ball
形状之前。
最后它应该是这样的:
\draw[dashed] \firstellipse; % <-- also the semicolon was missing in your code
\shade[ball color = gray!10] (0,0) circle (2cm);
结果是
1:顺便说一下,gray!100
给出的输出与 相同gray
。
答案2
您可以使用倒置夹。请注意,\def
您可以使用insert path
来将路径存储在宏或键中。
\documentclass[tikz,border=3mm]{standalone}
% https://tex.stackexchange.com/a/59168
\tikzset{reverseclip/.style={overlay,insert path={[reset cm]
(-16383.99999pt,-16383.99999pt) rectangle
(16383.99999pt,16383.99999pt)}}}
\begin{document}
\begin{tikzpicture}[c/.style={insert path={(0,0) circle[radius=2]}},
e/.style={insert path={(-1.5,0) circle[x radius=2,y radius=4]}}]
\draw[ball color = gray!100,fill opacity = 0.4,c];
\draw (-2,0) arc[start angle=180,end angle=360,x radius=2,y radius=0.6];
\draw[dashed] (2,0) arc[start angle=0,end angle=180,x radius=2,y radius=0.6];
\fill[fill=black] (0,0) circle (1pt);
\draw[dashed] (0,0 ) -- node[above]{$r$} (2,0);
\clip[c,reverseclip];
\draw[overlay=false,dashed,e];
\end{tikzpicture}
\end{document}