
但我需要在 中劃定 x, y 的圓[-2,6]
。
\begin{tikzpicture}
\draw[yellow!10, fill=hkvbluelogo!5](-2, -2) rectangle (6, 6);
\foreach \s in {0, 1, 2} {
\draw [lightgray] (0,0) circle (\s + 0.5);
\draw (0,0) circle (\s);
\draw [thick,color=red,domain=0:2*pi,samples=200,smooth] plot (xy polar cs:angle=\x r,radius=\s );
}
\end{tikzpicture}
我希望只在灰色部分繪製圓圈。
答案1
用作包含要剪切的內容(在本例中為圓圈)的環境\clip <path>;
中的第一個命令。scope
剪切路徑可以是任意路徑,但它不能設定任何附加樣式選項,這就是為什麼我們不能重複使用在其他地方繪製的彩色矩形。
\documentclass[tikz,border=2pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[yellow!10, fill=blue!10](-2, -2) rectangle (6, 6);
\begin{scope}
\clip (-2, -2) rectangle (6, 6);
\foreach \s in {0, 1, 2} {
\draw [lightgray] (0,0) circle (\s + 0.5);
\draw (0,0) circle (\s);
\draw [thick,color=red,domain=0:2*pi,samples=200,smooth] plot (xy polar cs:angle=\x r,radius=\s );
}
\end{scope}
\end{tikzpicture}
\end{document}