使用“for each”绘制复杂形状

使用“for each”绘制复杂形状

我正在尝试重现以下形状:

在此处输入图片描述

但效果不太好:

在此处输入图片描述

我正在尝试增加坐标,但似乎不起作用

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}

%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

\usepackage{tikz}%  permet de dessiner des figures, des graphiques
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre

%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)

\usepackage{xcolor}


\newdimen\R
\R=3cm
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}

\begin{tikzpicture}[font={\sansmath\sffamily\Large},thick, line cap=round, line width=0.4mm, line join=round, >=latex, x=1cm, y=1cm]


%\pic[fill=orange!20]{squaroid={width=4, height=4}};
\draw[] (0:\R) \foreach \x in {0,180,...,359}{
            --(\x:\R)
            --++(135+\x:{2*\R/5})
            arc (-45+\x:45+\x:\R/5-\R/60)
            arc (45+\x:135+\x:\R/5-\R*2/60)
            arc (135+\x:225+\x:\R/5-\R*3/60)
            arc (225+\x:315+\x:\R/5-\R*4/60)
            arc (315+\x:225+\x:\R/5-\R*5/60)
            arc (225+\x:135+\x:\R/5-\R*4/60)
            arc (135+\x:45+\x:\R/5-\R*4/60)
            arc (45+\x:-45+\x:\R/5-\R*3/60)
            arc (-45+\x:-225+\x:\R/5)
            --++(135+\x:{2*\R/5})
            --++(270+\x:{2*\R/5})
            arc (45+\x:-135+\x:\R/5)
            arc (-135+\x:-225+\x:\R/5-\R*3/60)
            arc (-225+\x:-315+\x:\R/5-\R*4/60)
            arc (-315+\x:-405+\x:\R/5-\R*4/60)
            arc (-405+\x:-495+\x:\R/5-\R*5/60)
            arc (-495+\x:-405+\x:\R/5-\R*4/60)
            arc (-405+\x:-315+\x:\R/5-\R*3/60)
            arc (-315+\x:-225+\x:\R/5-\R*2/60)
            arc (-225+\x:-135+\x:\R/5-\R*1/60)
            --+(-135+\x:{2*\R/5})
        } -- cycle 
        %(72:\R) node[above] {$n=5$} 
        ;
%\draw[-, opacity=0.8, samples=200, domain=-4:4, orange]
%    plot(\x,-1) coordinate node [label=a] {}
%    ;
%\draw[-, opacity=0.8, samples=200, domain=-4:4, blue]
%    plot(0,\x) coordinate node [label={[left, inner sep=6pt]b}] {}
%    ;
%\draw[-, opacity=0.8, samples=200, domain=-4:4, purple]
%    plot(\x,0) coordinate node [label=c] {}
%    ;
%\draw[-, opacity=0.8, samples=200, domain=-3:3, green]
%    plot(\x,\x) coordinate node [label=d] {}
%    ;
%\draw[]
%    (0,0) coordinate node[circle, fill=orange, draw=black, scale=.5, label={[above left, inner sep=6pt]O}] {}
%    (0,-1) coordinate node[circle, fill=orange, draw=black, scale=.5, label={[below right, inner sep=6pt]P}] {};
%draw the main coordinate system axes
%\pic at (0,0,0) {calcross};

%end
\end{tikzpicture}
\end{document}

答案1

为了从字面上回答关于 foreach 循环的问题,可以发布

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\R{3}
\draw (0:\R) \foreach \X in {0,...,3}{
            --(\X*90:\R)
            -- ++ (135+\X*90:{\R/2})
            foreach \Y in {1,...,5}
            {arc[start angle=-135+\Y*90+\X*90,end angle=-45+\Y*90+\X*90,
                radius=\R/5-\Y*\R/60]}
            arc[start angle=-135+6*90+\X*90,end angle=-45+7*90+\X*90,
                radius=\R/60]   
            foreach \Y in {5,...,0}
            {arc[start angle=-45+\Y*90+\X*90,end angle=-135+\Y*90+\X*90,
                radius=\R/5-\Y*\R/60-\R/30]}
            arc[start angle=-135+\X*90,end angle=-225+\X*90,
                radius=\R/5-\R/60]              
        } -- cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

但是,对于重复这样的任务,我更喜欢使用pics。如果你想要突出一些反射对称性,尤其如此,因为这些图片可以变换。也就是说,为了得到一些符合欧几里得变换的东西,你只需要用这些变换来处理它,直到你得到原始对象。这是群元素“旋转 90 度,然后绕 y 轴反射”的共轭类,即欧几里得群的 Z_4 子群。

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[pics/spiral/.style={code={
 \tikzset{spiral/.cd,#1}
 \def\pv##1{\pgfkeysvalueof{/tikz/spiral/##1}}
  \draw (0:{\pv{R}}) coordinate (-a) --
    plot[variable=\t,domain=0:\pv{tmax},samples=61,smooth]
    (\t:{\pv{r}-\pv{r}*abs(\t/\pv{trel})})
    -- ++({abs(\pv{tmax})+90}:1pt) \pgfextra{\pgfmathsetmacro{\myan}{abs(\pv{tmax})+90}}
    to[out=\myan,in=\myan]
   (\pv{tmax}:{\pv{r}+\pv{dr}-\pv{r}*abs(\pv{tmax}/\pv{trel})}) --
   plot[variable=\t,domain=\pv{tmax}:-180,samples=61,smooth]
   (\t:{\pv{r}+\pv{dr}-\pv{r}*abs(\t/\pv{trel})})
   -- (-180:\pv{R}) coordinate (-b);
  }},
  spiral/.cd,tmax/.initial=-630,trel/.initial=450,dr/.initial=0.1,
  r/.initial=1,R/.initial=2]
 \begin{scope}[rotate=45,transform shape,line cap=rect,thick,
    spiral/.cd,r=0.6,trel=720,R=1.5]
  \path (90:1.5) pic{spiral} 
    (180:1.5) pic[rotate=90,xscale=-1]{spiral}
    (270:1.5) pic[rotate=180,scale=-1]{spiral}
    (0:1.5) pic[rotate=270,yscale=-1]{spiral};  
 \end{scope}
 \draw[red] (-90:3) -- (90:3) node[pos=1.05] {$\mathsf{a}$}
  (45:3) -- (-135:3) node[pos=1.05] {$\mathsf{c}$};
 \draw[green!60!black] (180:3) -- (0:3) node[pos=1.05] {$\mathsf{b}$}
  (-45:3) -- (135:3) node[pos=1.05] {$\mathsf{d}$};
 \node[fill,circle,inner sep=2pt,label=below left:$O$] {};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

你画虚线圆圈来引导你

\documentclass[tikz,border=9]{standalone}

\begin{document}

\tikz{
    \draw[dotted]
        (0,0)foreach\r in{1,3,...,9}{circle(\r)}
        (0,2)foreach\r in{1,3,...,9}{circle(\r)};
    \draw[red]
        foreach\r in{1,3,...,9}{(0,-\r)arc(-90:90:\r)}
        foreach\r in{1,3,...,9}{(0,\r+2)arc(90:270:\r)}
    ;
}

\end{document}

相关内容