我在下面画了一个正方形,正方形里面有一个四分之一圆,我该如何填充四分之一圆?
\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
\draw (A) -- (B);
\draw (B) -- (C);
\draw (C) -- (D);
\draw (D) -- (A);
\draw (2, 3) arc[black, start angle=180, end angle=270, radius=1];
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
\draw (A) -- (B);
\draw (B) -- (C);
\draw (C) -- (D);
\draw (D) -- (A);
\draw[fill=pink] (2,3) arc[start angle=180, end angle=270, radius=1] -- (3,3) -- cycle;
\end{tikzpicture}
\end{document}
答案2
遵循 Qrrbrbirlbel 的建议后,以前的代码可以简化为:
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (C) at (3,3);
\draw[path picture={\draw[fill=red!30]
(path picture bounding box.north east) circle (1cm);}] (A) rectangle (C);
\end{tikzpicture}
原始答案
为了好玩,我们来看一下更复杂的解决方案。背景层上有一个完整的圆,但被矩形剪裁了。圆必须在背景上,以避免重新绘制被填充颜色覆盖的角。
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (C) at (3,3);
\draw (A) rectangle (C);
\begin{scope}[on background layer]
\clip (A) rectangle (C);
\draw[fill=pink] (C) circle[radius=1];
\end{scope}
\end{tikzpicture}
\end{document}