如何在 tikz 中为这些区域添加阴影?

如何在 tikz 中为这些区域添加阴影?

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}

\title{Your Paper}
\author{You}

\begin{document}

\begin{tikzpicture}
\draw (10.,6.) -- (4.,6.) -- (4.,0.) -- (10.,0.) -- cycle;
\draw(7.,3.) circle (3.cm);
\draw [shift={(7.,6.)}] plot[domain=-3.141592653589793:0.,variable=\t]({1.*3.*cos(\t r)+0.*3.*sin(\t r)},{0.*3.*cos(\t r)+1.*3.*sin(\t r)});
\draw [shift={(7.,0.)}] plot[domain=0.:3.141592653589793,variable=\t]({1.*3.*cos(\t r)+0.*3.*sin(\t r)},{0.*3.*cos(\t r)+1.*3.*sin(\t r)});
\draw [shift={(4.,3.)}] plot[domain=-1.5707963267948966:1.5707963267948966,variable=\t]({1.*3.*cos(\t r)+0.*3.*sin(\t r)},{0.*3.*cos(\t r)+1.*3.*sin(\t r)});
\draw [shift={(10.,3.)}] plot[domain=1.5707963267948966:4.71238898038469,variable=\t]({1.*3.*cos(\t r)+0.*3.*sin(\t r)},{0.*3.*cos(\t r)+1.*3.*sin(\t r)});
  \begin{scriptsize}
  \draw  (10.,6.) circle (1.05pt);
  \draw  (4.,6.) circle (1.05pt);
  \draw  (4.,0.) circle (1.05pt);
  \draw  (10.,0.) circle (1.05pt);
  \draw  (7.,6.) circle (1.005pt);
  \draw  (4.,3.) circle (1.05pt);
  \draw (7.,0.) circle (1.05pt);
  \draw  (10.,3.) circle (1.05pt);
  \end{scriptsize}
\end{tikzpicture}
\end{document}

答案1

简短而甜蜜...

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}
  \fill [blue!50!cyan] 
    (0,0) arc (90:0:1) -- (1,0) arc (0:120:1) arc (60:0:1) -- cycle
    (-1,-1) -- (-1,0) arc (180:210:1) arc (150:180:1);
  \draw circle [radius=1] (-1,-1) rectangle (1,1)
    (-1,-1) arc (180:0:1) arc (270:90:1) arc (360:180:1) arc (90:-90:1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

...不那么短,但更加花哨:

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}[c/.code={%
  \pgfmathsetmacro\r{rnd}\pgfmathsetmacro\g{rnd}\pgfmathsetmacro\b{rnd}%
  \definecolor{.}{rgb}{\r,\g,\b}%
  \pgfsetfillcolor{.}%
}]
\foreach \i in {0,...,3}{
\tikzset{rotate=\i*90}
\fill [c] (0:0)  arc (270:330:1) arc (30:60:1)   arc (120:180:1) -- cycle;
\fill [c] (30:1) arc (330:360:1) arc (90:120:1)  arc (60:30:1)   -- cycle;
\fill [c] (0:1)  arc (0:30:1)    arc (330:360:1) -- cycle;
\fill [c] (90:1) arc (90:60:1)   arc (120:90:1)  -- cycle;
\fill [c] (60:1) arc (60:120:1)  arc (60:0:1)    arc (180:120:1) -- cycle; 
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

编码虽然不太整齐,但是给出了所需的图片。

\documentclass[tikz,border=5]{standalone}

\begin{document}
  \begin{tikzpicture}
    \clip (-0.5\pgflinewidth,-0.5\pgflinewidth) rectangle
           ([shift={(0.5\pgflinewidth,0.5\pgflinewidth)}]2,2);
    \fill[olive] (0,0) rectangle (2,1);
    \fill[olive] (1,1) circle (1cm);
    \begin{scope}
      \clip (0,0) rectangle (1,2);
      \fill[white] (1,1) circle (1cm);
    \end{scope}
    \begin{scope}
      \clip (1,1) circle (1cm);
      \fill[olive] (1,2) circle (1cm);
    \end{scope}
    \begin{scope}
      \clip (0,1) rectangle (1,2);
      \fill[white] (0,1) circle (1cm);
    \end{scope}
    \fill[white] (1,0) circle (1cm);
    \draw (2,1) circle (1cm);
    \draw (0,1) circle (1cm);
    \draw (1,0) circle (1cm);
    \draw (1,2) circle (1cm);

    \draw (1,1) circle (1cm);
    \draw (0,0) rectangle (2,2);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容