如何绘制区域?

如何绘制区域?

我想画出这个形象

在此处输入图片描述

可是,我只能画图,不能绘画。

我的代码:

\documentclass[12pt]{article}

\usepackage{fontspec}

\usepackage[T1]{fontenc}

\usepackage[utf8]{inputenc}

\usepackage[portuguese]{babel}

\usepackage{color}

\usepackage{tikz}

\begin{document}

\begin{center}

    \begin{tikzpicture}[scale=1.5]

        \draw (-.5,-.5) rectangle (.5,.5);

        \draw (-1,-1) rectangle (1,1);

        \clip  (-1,-1) rectangle (1,1);

            \draw (1,1) circle (1);

            \draw (1,-1) circle (1);

            \draw (-1,-1) circle (1);

            \draw (-1,1) circle (1);

\end{tikzpicture}

\end{center}

\end{document}

在此处输入图片描述

答案1

如果你不介意用白色填充中心区域,这可能是一种方法。单独绘制每个圆弧,并用小正方形裁剪,然后在内部填充白色:

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage[T1]{fontenc}
\usepackage[portuguese]{babel}
\usepackage{tikz}

\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5]
        \draw (-1,-1) rectangle (1,1);
        \draw [fill=red] (0,1) arc (180:270:1) arc (90:180:1) arc (0:90:1) arc (-90:0:1);
        \draw [fill=blue] (-.5,-.5) rectangle (.5,.5);
        {\clip (-.5,-.5) rectangle (.5,.5);
        \draw [fill=white] (0,1) arc (180:270:1) arc (90:180:1) arc (0:90:1) arc (-90:0:1);}
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

答案2

如果要保留中心的颜色(或透明度),可以使用 绘制图形even odd rule。您必须重复该命令,首先填充中心矩形外的所有内容,然后使用路径帮助用另一种颜色填充内矩形角clip

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage[T1]{fontenc}
\usepackage[portuguese]{babel}
\usepackage{tikz}
        
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5]
    \draw[fill=green!10] (-1,-1) rectangle (1,1);
\end{tikzpicture}

\begin{tikzpicture}[scale=1.5]
    \draw[fill=green!10] (-1,-1) rectangle (1,1);
        
    \filldraw [fill=red, even odd rule] (-.5,-.5) rectangle (.5,.5) 
    (0,1) arc (180:270:1) arc (90:180:1) arc (0:90:1) arc (-90:0:1);
\end{tikzpicture}

\begin{tikzpicture}[scale=1.5]
    \draw[fill=green!10] (-1,-1) rectangle (1,1);
        
    \filldraw [fill=red, even odd rule] (-.5,-.5) rectangle (.5,.5) 
    (0,1) arc (180:270:1) arc (90:180:1) arc (0:90:1) arc (-90:0:1);

    \begin{scope}
        \clip (-.5,-.5) rectangle (.5,.5);
        \filldraw [fill=blue, even odd rule] (-.5,-.5) rectangle (.5,.5) 
        (0,1) arc (180:270:1) arc (90:180:1) arc (0:90:1) arc (-90:0:1);
    \end{scope}
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

相关内容