绘制四边都有圆的多边形

绘制四边都有圆的多边形

我希望制作一个正多边形,在其每条边上等距离地画出圆。

在此处输入图片描述

答案1

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

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture}
   \def\n{8}   % no. of sides
   \def\m{3}   % m+1 circles on each side
   \def\R{3}   % polygon's radius
   \def\r{.15} % circles' radii

   \begin{scope}
      [decoration={markings,
        mark=between positions 0 and {1-1/\m} step 1/\m
        with {
          \draw circle (\r);
        }
      }]

   \foreach[remember=\i as \oldi (initially 0)] \i in {0,...,\n} {
     % setting just 'decorate' instead will actually draw polygon
     \draw[postaction={decorate}] ({360/\n*\i}:\R) -- ({360/\n*\oldi}:\R);
   }     
   \end{scope}
\end{tikzpicture}

\end{document}

答案2

替代您的答案但基于此。

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

\usepackage{tikz}
\usetikzlibrary{decorations.markings,shapes.geometric}

\begin{document}

\begin{tikzpicture}
   \def\n{8}   % no. of sides
   \def\m{3}   % m+1 circles on each side
   \def\R{3}   % polygon's radius
   \def\r{.15} % circles' radii

   \begin{scope}
      [decoration={markings,
        mark=between positions 0 and {1-1/\m} step 1/\m
        with {
          \draw circle (\r);
        }
      },sides/.style={draw,postaction=decorate}]

   \pgfmathsetmacro{\m}{\m*\n}
   \node[regular polygon,regular polygon sides=\n,sides,minimum
   size=2*\R*1cm,rotate=360/16]{};
   \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容