如何使用 Tikz 为圆圈的一部分添加阴影?

如何使用 Tikz 为圆圈的一部分添加阴影?

在此处输入图片描述 您能演示一下如何使用 tikz 为圆圈内的区域添加阴影吗?

答案1

输出

图1

代码

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns, arrows.meta}

\begin{document}
\begin{tikzpicture}[scale=.5]

\draw[thick] (0,0) circle (5);
\draw[thick] (-5,0) -- (5,0);
\draw[thick] (0,-5) -- (0,5);

\node[draw, circle, thick, fill=white, minimum size=1mm, inner sep=0, label=225:O] at (0,0) {};


\draw[->, -{Stealth}] (6,0) -- (9,0);

\begin{scope}[xshift=15cm]
\path[clip, preaction={draw, thick}] (0,0) circle (5);
\fill[draw=black, thick, pattern=north west lines] (-5,2) -- (3,2) -- (3,-5) -- (-5,-5) -- cycle;
\fill[draw=black, thick, pattern=north west lines] (3,5) -- (3,2) -- (5,2) -- (5,5) -- cycle;

\node[draw, circle, thick, fill=black, minimum size=1mm, inner sep=0, label=225:O] at (0,0) {};
\draw[dashed] (-5,0) -- (5,0);
\draw[dashed] (0,-5) -- (0,5);

\draw[<->] (.5,2.3) -- (2.5,2.3) node[midway, above] {3cm};
\draw[<->] (3.3,1.7) -- (3.3,.2) node[midway, right] {2cm};
\end{scope}
\end{tikzpicture}
\end{document}

答案2

一种选择:绘制一个彩色圆圈,并使用该圆圈作为两个白色矩形的剪切路径

\documentclass[border=2mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[fill=red] circle (5cm);
\begin{scope}
\clip circle (5cm);
\draw[fill=white] (3,2) rectangle ++(5,5);
\draw[fill=white] (3,2) rectangle ++(-8,-8);
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

无需剪切(因此需要做更多工作)即可使用角度和圆弧:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{patterns,math}
\begin{document}
\begin{tikzpicture}[x=1em,y=1em,>=stealth]
\tikzmath{%
  integer \x, \y;
  \r = 5;
  \x = 3; \y = 2;
  \a = asin(\y/\r);
  \b = acos(\x/\r);
}
\draw circle [radius=\r];
\draw [gray, pattern=north west lines, pattern color=gray]
   (\x,\y) -- (\a:\r) arc (\a:\b:\r) -- (-\b:\r) arc (-\b:-180-\a:\r) -- cycle;
\draw [dashed] (-\r,0) -- (\r,0) (0,-\r) -- (0,\r);
\fill circle [radius=0.125] node [below left] {$O$};
\fill [fill=gray] (\x, \y) circle [radius=0.125] 
  node [above left] {$(\x,\y)$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容