
Я хочу нарисовать кольцевой генератор, т. е. нечетное число логических инверторов в кольце. У меня есть некоторые реальные проблемы с размещением кольца, соответствующим инверторам, см. прикрепленный код. Есть ли какие-либо предложения, как этого добиться?
\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
\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
узел not gate уже включает в себя прямые сегменты, от которых мы не можем легко избавиться.
Если вы не настроены использовать этот гейт и готовы обменять его на гейт not из pgf
библиотеки circuits.logic.US
, все немного проще. Единственная проблема в том, что center
якорь этого узла на самом деле не лежит в середине его input
и output
якорей, требуя дополнительных уловок, чтобы убедиться, что все входы и выходы действительно лежат на одном и том же цикле.
По этой причине я сначала рисую фиктивный узел, который я могу измерить, а затем вычислить правильную координату для каждого узла. Затем я могу использовать немного математики, чтобы вычислить правильный угол и радиус для каждой дуги, соединяющей ворота.
\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}