我使用了以下修改后的代码这个问题(经过修改,可以接受多次旋转)来绘制以下图案。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{verbatim}
\begin{document}
% ====================== begin spirosegment setting with nRotations ======================
\tikzset{pics/spirosegment/.style={code={
\tikzset{spirosegment/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spirosegment/##1}}
\pgfmathparse{(int(1/\pv{dx}+1)}
\tikzset{spirosegment/samples=\pgfmathresult}
\draw[trig format=rad,pic actions]
plot[variable=\t,domain=(\pv{xmin}-0.002:\pv{xmax}+0.002)*\pv{nRotations}, samples=\pv{samples}, smooth]
(
{(\pv{R}+\pv{r})*cos(\t)+\pv{p}*cos((\pv{R}+\pv{r})*\t/\pv{r})},
{(\pv{R}+\pv{r})*sin(\t)+\pv{p}*sin((\pv{R}+\pv{r})*\t/\pv{r})}
);
}},
spirosegment/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1, dx/.initial=0.01,samples/.initial=21,nRotations/.initial=1,domain/.code args={#1:#2}{%
\pgfmathparse{#1}\tikzset{spirosegment/xmin/.expanded=\pgfmathresult}
\pgfmathparse{#2}\tikzset{spirosegment/xmax/.expanded=\pgfmathresult}},
xmin/.initial=0,xmax/.initial=2*pi}
% ====================== end spirosegment setting nRotations ======================
\begin{frame}[t]
\frametitle{1}
\begin{center}
\vskip -.6cm
\begin{tikzpicture}[line width=.2mm]
\path (0,0)
foreach \X [count=\Y starting from 0] in {blue}
{pic[scale=0.5,draw=\X,ultra thick]{spirosegment={R=9.6,r=-3,p=2,nRotations=5,dx=0.001}}};
\end{tikzpicture}
\end{center}
\end{frame}
\begin{frame}[fragile,t]
\frametitle{2}
\begin{tikzpicture}[line width=.4mm]
\path (0,0)
pic[scale=0.3,draw=yellow]{spirosegment={dx=0.03}}
foreach \X [count=\Y starting from 0] in {blue,red,green,orange}
{pic[scale=0.3,draw=\X]{spirosegment={domain={-pi/12+\Y*pi/2}:{pi/12+\Y*pi/2}}}
};
\path[line cap=round] (6,0)
foreach \ScaleN [evaluate=\ScaleN as \Scale using {pow(0.85,\ScaleN)/0.8}]
in {1}
{foreach \Z in {0,...,3}
{foreach \X [count=\Y starting from 0] in
{yellow,orange,red,blue,purple,cyan,magenta,green!70!black}
{pic[scale=0.5,draw=\X,fill=\X!40,rotate=\Y*90/8+\Z*90, scale=\Scale,line width=\Scale*2pt]{spirosegment={domain={-pi/11.4}:{pi/11.4}}}
}}};
\end{tikzpicture}
\end{frame}
\end{document}
我尝试使用第二帧中使用的代码来分割第一帧中的图案,以生成以下图形,但我无法弄清楚如何计算生成它所需的公式,或者生成填充的尖峰。
答案1
抱歉,这又是向您现有的代码添加一些内容,而不仅仅是调整一些 pgf 值。我添加了一个closed
选项,最初是false
为了向下兼容。我还添加了一种nfill
循环显示 中定义的颜色的样式spiro colors
。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{verbatim}
\newif\ifspiroclosed
\begin{document}
% ====================== begin spirosegment setting with nRotations ======================
\tikzset{pics/spirosegment/.style={code={
\tikzset{spirosegment/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spirosegment/##1}}
\pgfmathparse{(int(1/\pv{dx}+1)}
\tikzset{spirosegment/samples=\pgfmathresult}
\draw[trig format=rad,pic actions]
plot[variable=\t,domain=(\pv{xmin}-0.002:\pv{xmax}+0.002)*\pv{nRotations}, samples=\pv{samples}, smooth]
(
{(\pv{R}+\pv{r})*cos(\t)+\pv{p}*cos((\pv{R}+\pv{r})*\t/\pv{r})},
{(\pv{R}+\pv{r})*sin(\t)+\pv{p}*sin((\pv{R}+\pv{r})*\t/\pv{r})}
)
\ifspiroclosed
-- ({(\pv{xmax}+\pv{xmin})/2}:\pv{rmin}) -- cycle
\fi;
}},
spirosegment/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1, dx/.initial=0.01,samples/.initial=21,nRotations/.initial=1,domain/.code args={#1:#2}{%
\pgfmathparse{#1}\tikzset{spirosegment/xmin/.expanded=\pgfmathresult}
\pgfmathparse{#2}\tikzset{spirosegment/xmax/.expanded=\pgfmathresult}},
xmin/.initial=0,xmax/.initial=2*pi,closed/.is if=spiroclosed,closed=false,
rmin/.initial=1}
% ====================== end spirosegment setting nRotations ======================
\tikzset{nfill/.code={%
\pgfmathtruncatemacro{\myind}{Mod(#1,dim({\pgfkeysvalueof{/tikz/spiro colors}}))}%
\pgfmathsetmacro{\mycolor}{{\pgfkeysvalueof{/tikz/spiro colors}}[\myind]}%
\tikzset{fill=\mycolor,fill opacity=0.5,draw=\mycolor}%
},spiro colors/.initial={"green","cyan","orange","gray!50"}}
\begin{frame}[fragile,t]
\frametitle{2}
\begin{tikzpicture}[line width=.4mm]
\path[blue] (0,0)
foreach \Y in {1,...,16}
{pic[scale=0.3,rotate=\Y*360/16]{spirosegment={%
domain={-pi/7.5}:{pi/7.5},closed,rmin=3.75}}
};
\path[line cap=round,line width=.2mm] (6,0)
foreach \Y in {1,...,16}
{pic[scale=0.3,rotate=\Y*360/16,nfill=\Y]{spirosegment={%
domain={-pi/7.5}:{pi/7.5},closed,rmin=3.75}}
};
\end{tikzpicture}
\end{frame}
\end{document}
答案2
这轮图我写的包,可以使用。
切片之间的间隙是通过键获得的gap
。
切片的形状由键slices inner arrow
和决定slices outer arrow
。
使用键值对来指定颜色列表WClistcolors
。这些颜色可以与宏一起使用\WClistcolors
。
切片的数量由键决定total count
。
\documentclass[border=6pt]{standalone}
\usepackage{wheelchart}
\begin{document}
\begin{tikzpicture}
\wheelchart[
gap,
radius={2.5}{2.5},
slices inner arrow={1}{0},
slices outer arrow={1.5}{0},
% slices={(-0.5,0)--(0,{2.5*tan(360/32)})--(0.8,0)--(0,{-2.5*tan(360/32)})--cycle;},
slices style={
fill=\WClistcolors!10,%none
draw=\WClistcolors,
%rounded corners
},
start half,
total count=16,
WClistcolors={green,cyan,orange,gray}
]{}
\end{tikzpicture}
\end{document}