有 DAC 和 DAC 形状吗circuitikz
?你知道,不规则五边形(边为三角形的线保证/矩形)。
尝试\pgfdeclareshape
为其编写一个,但想知道是否有人已经这样做了。
一个缺点是,如果您尝试从它画线,它会占用边界矩形。还\tip
为“三角形部分”的尖端设置一个锚点。
\tikzstyle{rectangulo}=[
draw, fill=#1, very thick, regular polygon, regular polygon sides=4,
text width=1cm, minimum width=2.25cm, minimum height=1.5cm,
outer sep=0, inner sep=0
]
\tikzstyle{DAC}=[
draw, fill=#1, very thick,
text width=1cm, minimum width=2.25cm, minimum height=1.5cm,
outer sep=0, inner sep=0%,
% path (-0.75cm,-0.75cm)
% -- (-1.50cm, 0 )
% -- (-0.75cm, 0.75cm)
% -- ( 0.75cm, 0.75cm)
% -- ( 0.75cm,-0.75cm)
% -- cycle;
]
\newcommand{\blocksDAC}[3]{%
\coordinate (D) at (#1,#2);
\node[rectangulo=pink!30,
outer sep=0] (#3) at (D) {};
\beginpgfgraphicnamed{#3}
\node[DAC=purple!10, shift=(D), draw=green, fill=none, name path=#3] (CCC) {}
(-0.75cm,-0.75cm)
-- (-1.50cm, 0 )
-- (-0.75cm, 0.75cm)
-- ( 0.75cm, 0.75cm)
-- ( 0.75cm,-0.75cm)
-- cycle;
\node[font=\Large] (Badc) at (D) {\texttt{ADC}};
\endpgfgraphicnamed
}%\blocksDAC
%------------------------------------------------------------------------------
\begin{document}
%------------------------------------------------------------------------------
\begin{center}
\begin{tikzpicture}[line width=0.5mm]
\blocksDAC{0}{-2}{Bdac}
\draw (Bdac) -- (5,0);
\end{tikzpicture}
\end{center}
%------------------------------------------------------------------------------
\ end{document}
%------------------------------------------------------------------------------
答案1
这是否接近您想要的?我在这里找到了模型模数转换器。正如所提到的,解决方案将两个终端元素circuitikz
之一修改 为两个宏,分别称为和,它们分别假设两个参数和。语法与下面的语法相同circuitikz
generic
myADC
myDAC
<name>
<color>
circuitikz
\draw (x1,y1) to[generic,color=white,name=<name>] (x2,y2);
\myadc{<name>}{<color>} % To replace the generic element
代码
\documentclass[border=5mm]{standalone}
\usepackage[american,siunitx]{circuitikz}
\newcommand{\myDAC}[2] % #1=name, #2=color
{
\draw[fill=#2] (#1) +(-16.5pt,0pt) --+(-6pt,6pt) --+(16.5pt,6pt) --+(16.5pt,-6pt) --+(-6pt,-6pt) --cycle;
\draw[] (#1)node{\tiny DAC};
}
\newcommand{\myADC}[2] % #1 = name, #2=color
{
\draw[fill=#2] (#1) +(-16.5pt,0pt) --+(-6pt,6pt) --+(16.5pt,6pt) --+(16.5pt,-6pt) --+(-6pt,-6pt) --cycle;
\draw[] (#1)node[]{\tiny ADC};
}
\begin{document}
%http://en.wikipedia.org/wiki/Analog-to-digital_converter
\begin{circuitikz}
\draw (3,4) to[generic,color=white,name=ADC] (5,4);
\myADC{ADC}{pink!30}
\draw (3,2) to[generic,color=white,name=DAC] (5,2);
\myDAC{DAC}{pink!30}
\end{circuitikz}
\end{document}
答案2
这将使用标准电路形状定义创建双极 ADC 和差分 ADC。
\documentclass{standalone}
\usepackage{circuitikz}
% normally defined in components.tex
\newlength{\ResUp} \newlength{\ResDown}
\newlength{\ResLeft} \newlength{\ResRight}
\newlength{\ResRadius} \newlength{\ResMiddle}
\makeatletter
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}
\def\CircDirection{\pgf@circ@direction}
\pgf@circ@Rlen = \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
\let\ResLen=\pgf@circ@Rlen
\makeatother
\newcommand{\Compass}% define anchors for compass points
{\anchor{north east}{\northeast}
\anchor{south west}{\southwest}
\anchor{north}{\pgfextracty{\ResUp}{\northeast}\pgfpoint{0cm}{\ResUp}}
\anchor{north west}{\pgfextracty{\ResUp}{\northeast}\pgfextractx{\ResLeft}{\southwest}\pgfpoint{\ResLeft}{\ResUp}}
\anchor{west}{\pgfextractx{\ResLeft}{\sosuthwest}\pgfpoint{\ResLeft}{0cm}}
\anchor{south}{\pgfextracty{\ResDown}{\southwest}\pgfpoint{0cm}{\ResDown}}
\anchor{south east}{\pgfextracty{\ResDown}{\southwest}\pgfextractx{\ResRight}{\northeast}\pgfpoint{\ResRight}{\ResDown}}
\anchor{east}{\pgfextractx{\ResRight}{\northeast}\pgfpoint{\ResRight}{0cm}}}
% ***************************** ADC *********************************
% extra anchors out,in1,in2,vref
\ctikzset{bipoles/ADC/width/.initial=1}
\ctikzset{bipoles/ADC/height/.initial=.5}
\ctikzset{bipoles/ADC/middle/.initial=-.25}
\ctikzset{bipoles/ADC/part/.initial=ADC}
\def\drawADC{% used by both bipole and node
\ResRight=\ctikzvalof{bipoles/ADC/width}\ResLen
\ResRight=0.5\ResRight
\ResLeft=-\ResRight
\ResUp=\ctikzvalof{bipoles/ADC/height}\ResLen
\ResUp=0.5\ResUp
\ResDown=-\ResUp
\ResMiddle=\ctikzvalof{bipoles/ADC/middle}\ResLen
\pgfpathmoveto{\pgfpoint{\ResLeft}{0pt}}
\pgfpathlineto{\pgfpoint{\ResMiddle}{\ResUp}}
\pgfpathlineto{\pgfpoint{\ResRight}{\ResUp}}
\pgfpathlineto{\pgfpoint{\ResRight}{\ResDown}}
\pgfpathlineto{\pgfpoint{\ResMiddle}{\ResDown}}
\pgfpathlineto{\pgfpoint{\ResLeft}{0pt}}
\pgfpathclose
\pgfusepath{draw}
\pgftext{\texttt{\ctikzvalof{bipoles/ADC/part}}}
}
\pgfcircdeclarebipole{}% no extra anchors for bipole version
{\ctikzvalof{bipoles/ADC/height}}
{ADC}
{\ctikzvalof{bipoles/ADC/height}}
{\ctikzvalof{bipoles/ADC/width}}
{\pgfsetlinewidth{\ctikzvalof{bipoles/thickness}\pgfstartlinewidth}\drawADC}
\def\ADCpath#1{\TikzBipolePath{ADC}{#1}}
\tikzset{ADC/.style = {\circuitikzbasekey, /tikz/to path=\ADCpath, l_=#1}}
\pgfdeclareshape{dADC}{%
\anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
\anchor{text} % this is used to center the text in the node
{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
\savedmacro{\resize}{ % called automatically
\ResRight=\ctikzvalof{bipoles/ADC/width}\ResLen
\ResRight=0.5\ResRight
\ResLeft=-\ResRight
\ResUp=\ctikzvalof{bipoles/ADC/height}\ResLen
\ResUp=0.5\ResUp
\ResDown=-\ResUp
\ResMiddle=\ctikzvalof{bipoles/ADC/middle}\ResLen
\ResRadius=\ResMiddle% location of in1 and in2
\advance\ResRadius by \ResLeft
\ResRadius=0.5\ResRadius
}% while these can be used for savedanchors, they will be fogotten by anchors
\savedanchor{\northeast}{\pgfpoint{\ResRight}{\ResUp}}
\savedanchor{\southwest}{\pgfpoint{\ResLeft}{\ResDown}}
\savedanchor\InOne{\pgfpoint{\ResRadius}{0.5\ResUp}}
\savedanchor\InTwo{\pgfpoint{\ResRadius}{0.5\ResDown}}
\savedanchor\Out{\pgfpoint{\ResRight}{0pt}}
\savedanchor\Vref{\pgfpoint{0pt}{\ResDown}}
\Compass% standard anchors
\anchor{in1}{\InOne}
\anchor{in2}{\InTwo}
\anchor{out}{\Out}
\anchor{vref}{\Vref}
\foregroundpath{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgflinewidth}
\drawADC}
}
\begin{document}
\begin{circuitikz}
\draw (0,0) to[ADC,o-*] (2,0);
\node[dADC] (ADC1) at (1,2) {};
\draw (ADC1.in1) -- +(-.5,0) node[left]{in1}
(ADC1.in2) -- +(-.5,0) node[left]{in2}
(ADC1.out) -- +(.5,0) node[right]{out}
(ADC1.vref) -- +(0,-.5) node[below]{vref};
\end{circuitikz}
\end{document}