如何在 tikz 中绘制圆角网格

如何在 tikz 中绘制圆角网格

正如标题所述,我想要只有最大的矩形圆角

在此处输入图片描述

这是我现在的代码

\begin{tikzpicture}[cell/.style={rectangle,draw=black,thin, minimum size=0.4cm}]
    \begin{scope}
        \node[cell,fill=red!20] at (0,0) {};
        \node[cell,fill=red!20] at (0.8,0) {};
        \node[cell,fill=red!20] at (0.4,0.4) {};
        \node[cell,fill=red!20] at (0,0.8) {};
        \node[cell,fill=red!20] at (0.8,0.8) {};

        \node[cell,fill=blue!30] at (0.4,0) {};
        \node[cell,fill=blue!30] at (0,0.4) {};
        \node[cell,fill=blue!30] at (0.8,0.4) {};
        \node[cell,fill=blue!30] at (0.4,0.8) {};
   \end{scope}
\end{tikzpicture}

我还想知道是否有更简单的方法来用自定义颜色填充网格。

答案1

一个没有节点的简单解决方案,就像我上面的评论中所说的那样:

\documentclass[tikz,border=3.141592mm]{standalone}
\usetikzlibrary{calc}

\begin{document}
    \begin{tikzpicture}[line width=1pt]
    
        \coordinate (A) at (0,0);
        \def\l{1} % length of one third of the grid
        
        \draw[rounded corners=3pt,fill=red!20] (A) rectangle++ (3*\l,3*\l);
        \foreach \x/\y in {1/0,0/1,1/2,2/1}
            \draw[fill=blue!20] ($(A)+(\x,\y)$) rectangle++ (\l,\l);

    \end{tikzpicture}
\end{document}

圆角网格

相关内容