foreach 循环中的节点放置

foreach 循环中的节点放置

此代码产生两个线圈绕组。如果我明确指定它们,它就可以正常工作。如果我将其包装在 foreach 循环中,它们就不会像应该的那样连接。我尝试改变线宽和预作用线宽。这不会影响错位。有人能看出问题吗?

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \tikzset{coil/.style={preaction={draw,line width=1mm,white},thick}}%
    \newlength{\coilradiusa}
    \newlength{\coilradiusb}
    \newlength{\coilradiusc}
    \newlength{\coilradiusd}
    \begin{tikzpicture}
        \pgfmathsetlength{\coilradiusa}{11.593 mm}
        \pgfmathsetlength{\coilradiusb}{3.42 mm}
        \pgfmathsetlength{\coilradiusc}{8.407 mm}
        \pgfmathsetlength{\coilradiusd}{2.48 mm}
        \newcommand{\iminusone}{0}
        \node[inner sep=0,outer sep=0,anchor=center] (0) at (0,0) {};
        \foreach \x in {1,...,2}{%
            \pgfmathsetmacro{\iminusone}{\x-1}
            \draw[coil] (\iminusone)
                arc[x radius=-\coilradiusb,y radius=\coilradiusa,start angle=0,delta angle=-180]
                arc[x radius=\coilradiusd,y radius=-\coilradiusc,start angle=0,delta angle=-180]
                node[inner sep=0,outer sep=0,anchor=center] (\x) {};
        }
    \end{tikzpicture}
    \begin{tikzpicture}
        \pgfmathsetlength{\coilradiusa}{11.593 mm}
        \pgfmathsetlength{\coilradiusb}{3.42 mm}
        \pgfmathsetlength{\coilradiusc}{8.407 mm}
        \pgfmathsetlength{\coilradiusd}{2.48 mm}
        \node[inner sep=0,outer sep=0,anchor=center] (0) at (0,0) {};
        \draw[coil] (0)
            arc[x radius=-\coilradiusb,y radius=\coilradiusa,start angle=0,delta angle=-180]
            arc[x radius=\coilradiusd,y radius=-\coilradiusc,start angle=0,delta angle=-180]
            node[inner sep=0,outer sep=0,anchor=center] (1) {};
        \draw[coil] (1)
            arc[x radius=-\coilradiusb,y radius=\coilradiusa,start angle=0,delta angle=-180]
            arc[x radius=\coilradiusd,y radius=-\coilradiusc,start angle=0,delta angle=-180]
            node[inner sep=0,outer sep=0,anchor=center] (2) {};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容