CircuitTikZ-環形振盪器

CircuitTikZ-環形振盪器

我想畫一個環形振盪器,也就是環形中的奇數個邏輯反相器。我在將環很好地對應於逆變器時遇到了一些真正的麻煩,請參閱隨附的程式碼。有什麼建議如何實現這一目標嗎?

    \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門節點已經包含了我們無法輕易去除的直線段。

如果您不打算使用此門並且願意從pgfcircuits.logic.US庫中換取非門,那麼事情會變得容易一些。唯一的問題是該節點的錨點實際上並不位於其錨點和錨點center的中間,需要更多的技巧來確保所有輸入和輸出實際上位於同一個圓上。inputoutput

因此,我首先繪製一個可以測量的假節點,然後計算每個節點的正確座標。然後我可以使用一些數學計算出連接門的每個弧的正確角度和半徑。

\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 個門

相關內容