
Quero desenhar um oscilador em anel, ou seja, um número ímpar de inversores lógicos em um anel. Tenho alguns problemas reais para colocar o anel que corresponde bem aos inversores, veja o código em anexo. Existe alguma sugestão de como conseguir isso?
\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}
Responder1
Usar coordenadas polares seria uma maneira de fazer isso:
\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}
Usando a \foreach
macro loop, podemos evitar o código repetido:
\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}
Conseguir um círculo perfeito é mais difícil. Um problema é que o circutikz
nó not gate já inclui segmentos de linha reta dos quais não podemos nos livrar facilmente.
Se você não está pronto para usar este portão e está disposto a trocar pelo portão not da biblioteca pgf
de circuits.logic.US
, as coisas são um pouco mais fáceis. O único problema é que a âncora deste nó center
não está realmente no meio de suas âncoras input
e output
, exigindo mais alguns truques para garantir que todas as entradas e saídas realmente estejam no mesmo ciclo.
Por esse motivo, primeiro desenho um nó falso que posso medir e depois calculo a coordenada correta para cada nó. Posso então usar um pouco de matemática para descobrir o ângulo e o raio corretos para cada arco que conecta os portões.
\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}