绕原点的顺时针和逆时针路径

绕原点的顺时针和逆时针路径

我想画以下 在此处输入图片描述

起初我想到做一些像偶极子的东西,但后来我意识到它不是那样的,它只是一条以顺时针或逆时针方向返回坐标原点的曲线。我的错误尝试是

\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{decorations.markings,arrows.meta,bending,shapes.misc}
\tikzset{% 
    attach arrow/.style={
    decoration={
        markings,
         mark=at position 0 with {\pgfextra{%
         \pgfmathsetmacro{\tmpArrowTime}{\pgfkeysvalueof{/tikz/arc arrow/length}/(\pgfdecoratedpathlength)}%
         \xdef\tmpArrowTime{\tmpArrowTime}}},
        mark=at position {#1-3*\tmpArrowTime} with {\coordinate(@1);},
        mark=at position {#1-2*\tmpArrowTime} with {\coordinate(@2);},
        mark=at position {#1-1*\tmpArrowTime} with {\coordinate(@3);},
        mark=at position {#1+\tmpArrowTime/2} with {\coordinate(@4);
        \draw[-{Stealth[length=\pgfkeysvalueof{/tikz/arc arrow/length},bend]}] plot[smooth]
         coordinates {(@1) (@2) (@3) (@4)};},
        },
     postaction=decorate,
     },
     attach arrow/.default=0.5,
     arc arrow/.cd,length/.initial=2mm,
}
\begin{document}
\begin{tikzpicture}
  \foreach \x in {0,1}
  \draw[red,thick,attach arrow/.list={1/4}] (0,\x) circle [radius=\x+1];
\end{tikzpicture}
\end{document}

答案1

\loops这是一个绘制图形的宏。\loops{2}\hspace{2cm}\loops[<]{4}产生以下内容:

在此处输入图片描述

必需参数是围绕原点的循环次数。可选参数<表示顺时针方向,空表示逆时针方向。

\documentclass{article}

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

\tikzset{mycurve/.style={thick, looseness=1.7, decoration={markings, mark=at position 0 with {\arrow{#1}}}, postaction={decorate}},
    mycurve/.default={>}}
    
\newcommand{\loops}[2][>]{\begin{tikzpicture}[baseline]
\foreach \x[evaluate=\x as \xx using {1+mod(int(\x),#2)}] in {1,...,#2}{
\draw[mycurve=#1](\x,0)to[out=90, in=90](-\x,0);
\draw[mycurve=#1](-\x,0)to[out=-90, in=-90](\xx,0);
}
\end{tikzpicture}}

\begin{document}

\loops{2}\hspace{2cm}\loops[<]{4}

\end{document}

为了获得更紧凑的外观,您可以更改\draw命令:

\draw[mycurve=#1](.5+.5*\x,0)to[out=90, in=90](-.5-.5*\x,0);
\draw[mycurve=#1](-.5-.5*\x,0)to[out=-90, in=-90](.5+.5*\xx,0);

在此处输入图片描述

相关内容