CircuiTikZ-环形振荡器

CircuiTikZ-环形振荡器

我想画一个环形振荡器,即奇数个逻辑反相器组成一个环形。我在将环形振荡器与反相器完美对应放置时遇到了一些麻烦,请参阅所附代码。有什么建议可以实现这一点吗?

    \begin{center}\begin{circuitikz}
\draw
    (0,3) node[not port,rotate=-360] (mynot1) {}
    (2.2,1.4) node[not port,rotate=-72] (mynot2) {}
    (2,-1.4) node[not port,rotate=-144] (mynot3) {}
    (-2,-2) node[not port,rotate=-206] (mynot4) {}
    (-2.2,1.4) node[not port,rotate=-288] (mynot5) {}
    (mynot1.out) to[bend left] (mynot2.in)
    (mynot2.out) to[bend left] (mynot3.in)
    (mynot3.out) to[bend left] (mynot4.in)
    (mynot4.out) to[bend left] (mynot5.in)
    (mynot5.out) to[bend left] (mynot1.in);
    \end{circuitikz} \end{center}

在此处输入图片描述

答案1

使用极坐标是一种方法:

\documentclass[margin=5pt]{standalone}
\usepackage{circuitikz}

\begin{document}
    \begin{circuitikz}
        \draw (  -0:3) node[not port,rotate= -90] (mynot1) {}
              ( -72:3) node[not port,rotate=-162] (mynot2) {}
              (-144:3) node[not port,rotate=-234] (mynot3) {}
              (-216:3) node[not port,rotate=-306] (mynot4) {}
              (-288:3) node[not port,rotate=-378] (mynot5) {}
              (mynot1.out) to[bend left] (mynot2.in)
              (mynot2.out) to[bend left] (mynot3.in)
              (mynot3.out) to[bend left] (mynot4.in)
              (mynot4.out) to[bend left] (mynot5.in)
              (mynot5.out) to[bend left] (mynot1.in);
    \end{circuitikz}
\end{document}

输出

通过使用\foreach循环宏,我们可以避免重复的代码:

\文档类

\documentclass[margin=5pt][margin=5pt]{standalone}
\usepackage{circuitikz}

\begin{document}
    \begin{circuitikz}
        \foreach \i in {0,...,4} {
            \draw (-\i * 72:3) node[not port,rotate=-90 - \i * 72] (mynot\i) {};
        }
        \foreach[remember=\i as \j (initially 4)] \i in {0,...,4} {
            \draw (mynot\j.out) to[bend left] (mynot\i.in);
        }
    \end{circuitikz}
\end{document}

得到完美的圆比较困难。一个问题是非circutikz门节点已经包含了我们无法轻易去除的直线段。

如果您不打算使用此门,并且愿意从库中换取非门,事情会变得简单一些。唯一的问题是,此节点的锚点实际上并不位于pgf其和锚点的中间,需要更多的技巧来确保所有输入和输出实际上位于同一个环上。circuits.logic.UScenterinputoutput

因此,我首先绘制一个可以测量的假节点,然后计算每个节点的正确坐标。然后我可以使用一些数学运算来计算连接大门的每个弧的正确角度和半径。

\documentclass[margin=5pt]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{circuits.logic.US}

\begin{document}
    \begin{circuitikz}[not/.style={circuit logic US,not gate}]
        \newcommand\radius{2}
        \newcommand\ngates{5}

        % draw a hidden not gate so we can measure the distance between its input and output
        \begin{pgfinterruptboundingbox}
            \node[not,anchor=input,transform canvas={scale=0}] at (0, \radius) (dummynot) {};
        \end{pgfinterruptboundingbox}

        \foreach \i in {1,...,\ngates} {
            \draw let \p0 = (dummynot.output) in        % \x0 is now the "length" of the node, \y0 is the radius
                  (-\i * 360 / \ngates:\y0)             % this is the position on the circle
                  ++(-90 - \i * 360 / \ngates:-\x0 / 2) % this is the offset that makes the input and output lie at the same distance from the center
                  node[not,anchor=input,rotate=-90 - \i * 360 / \ngates] (mynot\i) {};
        }
        \foreach \i in {1,...,\ngates} {
            \draw let \p0 = (mynot\i.output),
                      \p1 = (mynot\i.input),
                      \p2 = (dummynot.output) in
                  (\p0) arc[start angle={atan2(\y0, \x0)},delta angle={2 * atan2(\x2 / 2, \y2) - 360 / \ngates},radius={veclen(\p0)}];
        }
    \end{circuitikz}
\end{document}

5 个门 11 个门 4 个门 2 个门 1 门

相关内容