这是这个问题。
他修改了运算放大器,使得积分器的矩形出现,但我遇到了问题。
人们给了我一个解决方案,即删除加号和减号(这是理想的)。但是,代码没有考虑用户想要的模拟加法器和积分器的输入数量(在 CircuiTikz 包中,可以指定逻辑门的输入数量)。在之前的代码中,人们只是在积分器的中间画了一条线,这不是我想要的;我想要一个输入从那里伸出来,这取决于输入的数量。
以下是我所拥有的:
对应方程:
我查看了 CircuiTikz 中的逻辑门代码以及代码中提供的解决方案,但语法对我来说非常不友好。有人可以提供代码来执行此操作并详细解释代码中使用的术语吗?我不知道许多术语是什么意思。
答案1
这是实现此目的的一种方式;我使用组件的边框引脚和外部引脚之间的差异muxdemux
来创建框。如果您保持和之间的比率不变NL
,您将获得美观的对象,当然,将“矩形绘制”封装到宏中也相当容易。Lh
w
\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\begin{document}
\begin{circuitikz}[
]
\tikzset{small text/.style={
font=\tiny,
right,
inner xsep=1pt,
},
}
% four input plain thing. I am using two pins more to give space
% for the text
\node[muxdemux, no input leads, muxdemux def={Lh=4, NL=6, w=4, Rh=0, NR=1}]
(A){adder};
\draw (A.blpin 2) node[small text]{$1$} -- ++(-1,0) node[left]{$u$};
\draw (A.blpin 3) node[small text]{$-1$} -- ++(-0.8,0);
\draw (A.blpin 4) node[small text]{$-1.2$} -- ++(-0.6,0);
\draw (A.blpin 5) node[small text]{$-1.2$} -- ++(-0.4,0);
\draw (A.brpin 1) -- ++(1,0) coordinate(one);
% integrator --- I use three input pins to build the rectangle
% I use the difference between border pin and exteral pin to build the
% square block
\node[muxdemux, no input leads, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1}, anchor=lpin 2]
(B) at(one) {$\int\quad$};
\draw[line width=0.8pt] (B.north west -| B.lpin 2) rectangle (B.south west -| B.blpin 2);
% notice that there is a small overshoot of the triangle for the line bevel. You can adjust for that if you want.
\draw (B.brpin 1) -- ++(1,0) coordinate(two);
\node [small text] at (B.lpin 2) {$1$};
% deriver ---
\node[muxdemux, no input leads, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1}, anchor=lpin 2]
(C) at(two) {$\frac{\mathrm{d}}{\mathrm{d}\,t}\quad$} ;
\draw[line width=0.8pt] (C.north west -| C.lpin 2) rectangle (C.south west -| C.brpin 1);
\node [small text] at (C.lpin 2) {$1$};
\draw (C.brpin 1) -- ++(1,0) coordinate(three);
\end{circuitikz}
\end{document}
为了使事情更紧凑,你可以使用薛定谔的猫的绝招和pics
;append after command
在这种情况下,你需要添加锚点遗漏的部分muxdemux
(我会在下一版本中添加它!):
\documentclass[border=10pt]{standalone}
\usepackage[siunitx, RPvoltages]{circuitikz}
\makeatletter
\def\pgfaddtoshape#1#2{% https://tex.stackexchange.com/a/14772/38080
\begingroup
\def\pgf@sm@shape@name{#1}%
\let\anchor\pgf@sh@anchor
#2%
\endgroup
}
% we need to add an anchor to muxdemux
\pgfaddtoshape{muxdemux}{
\anchor{top left ext}{%
\topleft\advance\pgf@x by -\extshift
}}
\makeatother
\begin{document}
\begin{circuitikz}[
]
\tikzset{small text/.style={
font=\tiny,
right,
inner xsep=1pt,
},
integral block/.style={append after command={%
pic{inputrect}}
},
derivative block/.style={append after command={%
pic{fullrect}}
},
pics/inputrect/.style={code={\let\mytikzlastnode\tikzlastnode
% adjust thickness
\draw[line width=0.8pt] (\mytikzlastnode.top left ext) rectangle (\mytikzlastnode.bottom left);}},
pics/fullrect/.style={code={\let\mytikzlastnode\tikzlastnode
% adjust thickness
\draw[line width=0.8pt] (\mytikzlastnode.top left ext) rectangle (\mytikzlastnode.south east);}},
}
% four input plain thing. I am using two pins more to give space
% for the text
\node[muxdemux, no input leads, muxdemux def={Lh=4, NL=6, w=4, Rh=0, NR=1}](A){adder};
\draw (A.blpin 2) node[small text]{$1$} -- ++(-1,0) node[left]{$u$};
\draw (A.blpin 3) node[small text]{$-1$} -- ++(-0.8,0);
\draw (A.blpin 4) node[small text]{$-1.2$} -- ++(-0.6,0);
\draw (A.blpin 5) node[small text]{$-1.2$} -- ++(-0.4,0);
\draw (A.brpin 1) -- ++(1,0) coordinate(one);
% integrator --- I use three input pins to build the rectangle
% I use the difference between border pin and exteral pin to build the
% square block
\node[muxdemux, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
no input leads, integral block,
anchor=lpin 2](B) at(one) {$\int\quad$};
% notice that there is a small overshoot of the triangle for the line bevel. You can adjust for that if you want.
\draw (B.brpin 1) -- ++(1,0) coordinate(two);
\node [small text] at (B.lpin 2) {$1$};
% deriver ---
\node[muxdemux, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
no input leads, derivative block,
anchor=lpin 2](C) at(two) {$\frac{\mathrm{d}}{\mathrm{d}\,t}\quad$};
\node [small text] at (C.lpin 2) {$1$};
\draw (C.brpin 1) -- ++(1,0) coordinate(three);
%
% you can also rotate them...
%
\draw (B.brpin 1) ++(0.5,0) -- ++(0,1) coordinate(four);
\node[muxdemux, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
no input leads, integral block,
anchor=lpin 2, rotate=90](D) at(four) {$\int\quad$};
\draw (B.brpin 1) ++(0.5,0) -- ++(0,-1) coordinate(five);
\node[muxdemux, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1},
no input leads, derivative block,
anchor=lpin 2, rotate=-90](D) at(five) {$\frac{\mathrm{d}}{\mathrm{d}\,t}\quad$};
\end{circuitikz}
\end{document}