1

I am trying to draw analog computer symbols (I will put a picture of the entire list later). Right now, I am trying to draw a symbol of an analog integrator. Here's what I have right now in code:

\documentclass[12pt]{article}

\usepackage{amssymb, graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{float}
\usepackage{enumitem}
\usepackage{amsfonts,bm}
\usepackage{diagbox}
\usepackage[makeroom]{cancel}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}
\usepackage[american,siunitx]{circuitikz}
\usepackage[export]{adjustbox}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\usepackage{units}
\usepackage{relsize}
\usepackage[margin=1in]{geometry}

\begin{document}

    \tikzstyle{block} = [draw, rectangle, 
    minimum height=3em, minimum width=3em]
    \tikzstyle{sum} = [draw, circle, node distance=1cm]
    \tikzstyle{input} = [coordinate]
    \tikzstyle{output} = [coordinate]
    \tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
    \begin{figure}[H]
            \centering
            % The block diagram code is probably more verbose than necessary
            \begin{tikzpicture}[auto, node distance=2cm,>=latex']
                \node[regular polygon,regular polygon sides=3, draw, shape border rotate=-90, scale = 2.5, name = integrator]{};
                \draw (integrator.corner 2) -- ++ (-0.5, 0) |- (integrator.corner 3);
            \end{tikzpicture}
            \caption{Control block diagram.}
        \end{figure}

\end{document}

Here's what I have right now:

enter image description here

Right now, the lines aren't properly connecting to the vertices as I want. Is there a way to properly connect them such that there isn't any space in between the lines and the corners?

Edit: here is a list of analog computer symbols so one can understand what I am trying to do for the integrator (and the derivative): enter image description here

Another example (which is seeemingly done on LaTeX):

enter image description here

Update: here is my example circuit that I want to draw on LaTeX:

enter image description here

Corresponding equation is here:

enter image description here

Can someone show me how to generalize the number of inputs to the summer and integrator with detailed explanation on the syntax? I tried to follow the code, but the syntax is super gnarly and very user unfriendly.

Superman
  • 1,615
  • 1
    With editing your question you actual ask new question. Please, consider to ask new one as follow-up question to this one. – Zarko Feb 26 '20 at 23:37

1 Answers1

3

I think all of that can be achieved with circuitikz. Here are two examples. BTW, \tikzstyle is deprecated.

\documentclass{article}
\usepackage{amsmath}
\usepackage[american,siunitx]{circuitikz}
\begin{document}
\begin{circuitikz}
 \draw (0,0) to[amp,t=$\boldsymbol{K}$] ++(3,0); 
 \ctikzset{amplifiers/minus={$k_1$},amplifiers/plus={$k_2$}}
 \draw (0,-1.5) -- ++(1,0) node[op amp, anchor=-](sum){};
 \tikzset{cop amp/.style 2 args={op amp,
 /utils/exec=\ctikzset{amplifiers/minus={},amplifiers/plus={}},
 append after command={%
 pic{rect={#1}{#2}}
 }},
 pics/rect/.style 2 args={code={\let\mytikzlastnode\tikzlastnode
 \draw[thick,fill=white] (\tikzlastnode.bin up|-\tikzlastnode.north) 
 -- ++({-1.1*max(width("#1"),width("#2"))-8pt},0) |- (\tikzlastnode.bin up|-\tikzlastnode.south)
 -- cycle;
 \path (\mytikzlastnode.bin up) node[left=0pt,font=\boldmath] {#1}
  (\mytikzlastnode.bin down) node[left=0pt,font=\boldmath] {#2};
 }}}
 \draw (1,-4)  node[cop amp={$k_1$}{$k_2$}, anchor=-](sum){};
\end{circuitikz}
\end{document}

enter image description here

Let me try to explain what

\tikzset{cop amp/.style 2 args={op amp,
 /utils/exec=\ctikzset{amplifiers/minus={},amplifiers/plus={}},
 append after command={%
 pic{rect={#1}{#2}}
 }},
 pics/rect/.style 2 args={code={\let\mytikzlastnode\tikzlastnode
 \draw[thick,fill=white] (\tikzlastnode.bin up|-\tikzlastnode.north) 
 -- ++({-1.1*max(width("#1"),width("#2"))-8pt},0) |- (\tikzlastnode.bin up|-\tikzlastnode.south)
 -- cycle;
 \path (\mytikzlastnode.bin up) node[left=0pt,font=\boldmath] {#1}
  (\mytikzlastnode.bin down) node[left=0pt,font=\boldmath] {#2};
 }}}

does. It defines a modified op amp node. It uses this node, hence the op amp key. Then it it removes the + and - with /utils/exec=\ctikzset{amplifiers/minus={},amplifiers/plus={}}. (One may argue that using /utils/exec is not always optimal. I agree with Henri on that. However, TikZ even uses it internally, i.e. it can be found in tikz.code.tex. I think here it is fine.) The main ingredient is the append after command key, which issues a pic that adds the rectangle. The rectangle gets attached to the node, the name of which is stored in \tikzlastnode. Since we are adding other nodes, it gets stored on \mytikzlastnode. By measuring the size of the arguments we can make sure that the rectangle is large enough. One could also use fit here.

Below is an edit by Eduardo Alves da Silva, thanks a lot!

EDIT : Regarding on how to use, for example, to make the image you've provided:

\documentclass[border = 5pt]{standalone}
\usepackage[RPvoltages]{circuitikz}
\usepackage{calc}
\usepackage{tikz}
\tikzset{cop amp/.style 2 args={op amp,
    /utils/exec=\ctikzset{amplifiers/minus={},amplifiers/plus={}},
    append after command={%
        pic{rect={#1}{#2}}
}},
pics/rect/.style 2 args={code={\let\mytikzlastnode\tikzlastnode
        \draw[thick,fill=white] (\tikzlastnode.bin up|-\tikzlastnode.north) 
        -- ++({-1.1*max(width("#1"),width("#2"))-8pt},0) |- 
(\tikzlastnode.bin up|-\tikzlastnode.south)
        -- cycle;
        \path (\mytikzlastnode.bin up) node[left=0pt,font=\boldmath] {#1}
        (\mytikzlastnode.bin down) node[left=0pt,font=\boldmath] {#2};
}}}
\begin{document}
\begin{circuitikz} [american voltages]
    \node[draw,minimum size,fill=white] (-1) {-1};
    \draw (-1.east) to[short,-] ++(1,0)
    node[draw, circle,anchor=west] (g) {g};
    \draw (g.east) to[short] ++(0.5,0) node[cop amp={}{}, anchor=-](int1){};
    \draw (int1.out) to[short] ++(1,0) coordinate (aux) to[short] ++(1,0) node[cop amp={}{}, anchor=west] (int2) {};
    \draw (aux) to[short,*-] ++(0,-2) coordinate (aux2);
    \draw[-] (aux2) -- ++(-2,0) node[draw,circle,anchor=east] (dm) {$d/m$};
    \draw[-] (dm) --++(-1.5,0) coordinate (aux2);
    \draw[-] (aux2) |- (int1.+);
    \draw (aux) node[above] () {$-\dot{y}$};
    \draw (int2.out) to[short] ++(0.5,0) node[above] () {$y$};
    \draw (int2.out) to[short, *-] ++(0,-3.5) to[short] ++(-1,0) node[buffer,xscale=-1,anchor=in] (buffer) {};
    \draw (buffer.out) to[short] ++(-0.5,0) node[above] () {$-y$};
    \draw (buffer.out) to[short] ++(-1,0) node[draw,circle,anchor=east] (cm) {$c/m$};
    \draw (cm.west) to[short] ++(-3.5,0) coordinate (aux) to[short] (aux |- int1.west)
    to[short] (int1.west);
\end{circuitikz}
\end{document}

enter image description here

Zarko
  • 296,517
  • Ok, got it, but for the "differential" amplifier below, how do you connect the top and bottom corners of the vertices as shown in my drawing? Here's a link that has another example: https://en.wikipedia.org/wiki/Analog_computer#/media/File:Federpendel_als_Analogrechenschaltung.png – Superman Feb 18 '20 at 02:27
  • @Superman I am sorry, I cannot follow. Which of your and my symbols are you talking about? –  Feb 18 '20 at 02:31
  • I am trying to refer to the integrator symbol in my drawing and the "differential amplifier" symbol. – Superman Feb 18 '20 at 02:32
  • Hi, Schrodinger's cat, can you explain the code for the third drawing that you did, line by line? I would like to understand the meaning of each line, since the syntax is quite gnarly. Also, how do I vary the number of bins (e.g. 3 instead of 2, as indicated in the spring-mass-damper diagram)? – Superman Feb 18 '20 at 04:10
  • Hello, thanks a lot for explaining! Btw, in the code that modifies the op amp, is there a way to specify the number of inputs? I know that when defining logic & and or gates, one can specify the number of inputs as parameters. Is there a similar way to somehow parametrize the number of inputs for the modified "op-amp"? – Superman Feb 20 '20 at 19:04
  • In the code that modifies the op amp, is there a way to specify the number of inputs? I know that when defining logic & and or gates, one can specify the number of inputs as parameters. Is there a similar way to somehow parametrize the number of inputs for the modified "op-amp"? This question has not been answered. In other words, what if I want 4 inputs? There's gotta be a way to parametrize the inputs. – Superman Feb 26 '20 at 22:55