答案1
更新: 这是一个更可配置的解决方案,并且在数学方面也更容易。
为此,我制作了两个\pics
,一个用于“花瓣”,另一个用于重复和旋转花瓣的“花”。
像这样:
\documentclass[tikz,border=2mm]{standalone}
\tikzset
{
pics/petal/.style 2 args={% #1 = radius, #2 = distance to the next petal
code={
\pgfmathsetmacro\half{0.5*#2}
\ifdim\half pt<#1 pt % if the petals intersect
\pgfmathsetmacro\aa{acos(\half/#1)}
\path[pic actions] (\aa:#1) arc (\aa:360-\aa:#1) arc (180+\aa:180-\aa:#1);
\else % if the petals don't intersect
\draw[pic actions] (0,0) circle [radius=#1];
\fi
}},
pics/flower/.style n args={3}{% #1 = flower radius, #2 = petal radius, #3 = number of petals
code={
\pgfmathsetmacro\dd{#1*sqrt(2*(1-cos(360/#3))} % distance between petals
\foreach\i in {1,...,#3}
\pic[draw,fill,rotate=180/#3+360*\i/#3+90] at (360*\i/#3:#1) {petal={#2}{\dd}};
}},
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
\foreach\i in {1,...,4}
\pic[fill=green!20,rotate=90*\i+180] at (90*\i:4) {petal={1}{1}};
\pic[draw=red ,fill=red!20] {flower={3}{1}{12}};
\pic[draw=blue,fill=blue!10] {flower={3}{0.2}{4}};
\pic[draw=blue,fill=blue!30] {flower={1}{0.2}{20}};
\foreach\i in {1,...,12}
\pic[fill=yellow,rotate=30*\i] at (30*\i:3) {flower={0.4}{0.1}{7}};
\end{tikzpicture}
\end{document}
初步回答:
我正在创建一个\pic
只绘制圆的可见部分的程序(我认为,这与 mickep 提出的想法相同)。然后我每次绘制它并旋转。
它需要使用余弦定理计算几个角度(例如)。
这是我的解决方案:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\n{20}
\pgfmathsetmacro\a{360/\n}
\pgfmathsetmacro\aa{acos(4*cos(\a)-3)} % some other angles
\pgfmathsetmacro\bb{90-0.5*\aa} % obtained from the
\pgfmathsetmacro\cc{0.5*\aa-0.5*\a} % cosine theorem
\tikzset
{% a pic (like a crescent moon)
pics/moon/.style={
code={
\path[pic actions] (0:2) ++ (180-\cc:1) arc (180-\cc:540-\cc-2*\bb:1) arc (\a-180+\cc+2*\bb:\a-180+\cc:1);
}},
}
\foreach \i in {1,...,\n}
\pic[draw,fill=yellow,rotate=\a*\i] (\a*\i:2) {moon};
\end{tikzpicture}
\end{document}
或者,改变
\def\n{8}
....
\pic[draw=red,thick,fill=orange!30,rotate=\a*\i] (\a*\i:2) {moon};
....
答案2
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\n{20}
\def\a{360/\n}
\foreach \i in {1,...,\n}
\draw[fill=yellow] (\i*\a:2) circle[radius=1];
\clip (0,-3) rectangle (3,3);
\foreach \i in {1,...,\n}
\draw[fill=yellow] ({int(\i-\n/2)*\a}:2) circle[radius=1];
\end{tikzpicture}
\end{document}
答案3
因为您现在知道了 tikz 答案对您有用,下面是我在评论中用于绘制图像的代码:
\startMPpage[offset=1dk]
numeric N ; N := 20 ;
path c[] ;
c[1] := fullcircle rotated 180 scaled 2cm yshifted 2cm ;
c[2] := reverse c[1] rotated (360/N) ;
c[3] := buildcycle(c[1],c[2]) ;
for i = 0 upto N - 1:
fill c[3] rotated (i*360/N) withcolor yellow ;
draw c[3] rotated (i*360/N) ;
endfor
fill c[3] withcolor darkgreen ;
draw c[3] withcolor darkred ;
\stopMPpage
一些评论:
- 最后的填充和绘制当然只显示所使用的绿色和红色部分。
- 和
rotated 180
的reverse
存在只是为了buildcycle
选择正确的部分。
我注意到yellow
tikz 和 MetaPost 中的颜色不同。这对我来说是新鲜事。