4

I'm trying to typeset the following image using Tikz:How it should look like

I have tried many options, but there doesn't seem to be any good solution doing this an efficient way. My code I used at last:

\begin{tikzpicture}
    \draw (0.2,1.75) -- (7,1.75);
    \draw (0.2,2.5) -- (7,2.5);
    \draw (0.2,3.25) -- (7,3.25);
    \draw (2,1) -- (2,3.75);
    \draw (4,1) -- (4,3.75);
    \draw (6,1) -- (6,3.75);

    % the code which I tried last to get this (only first column)
    % incomplete, as I didn't get the results I wished
    \draw[rotate=45] (3.25,0.95) ellipse (1mm and 0.5mm);
    \draw[rotate=45] (2.75,0.4) ellipse (1mm and 0.5mm);
    \draw[rotate=45] (2.25,-0.15) ellipse (1mm and 0.5mm);
    \draw (1.4,3.25) -- (1.6,3);
    \draw (1.65,2.9) -- (2,2.75);
\end{tikzpicture}

enter image description here

Is there a easier and better solution to do this?

5

I made two pic's for the different connection types (element A and element B) which are positioned at the cross points of the lines:

enter image description here

\documentclass{article}

\usepackage{tikz}

\begin{document}

\tikzset{
  element A/.pic={
    \begin{scope}[rotate=45,shift={(180:0.5cm)}]
    \draw[thick] (0,-0.5) -- (0,0.5);
    \fill (0,-0.5) circle [radius=1mm] (0,0.5) circle [radius=1mm];
    \path[draw,fill=white,thick] (-0.3,0.10) arc[start angle=180,end angle=360,radius=3mm] -- cycle;
    \end{scope}
  },
  element B/.pic={
    \begin{scope}[rotate=45,shift={(180:0.5cm)}]
    \draw[thick] (0,0) -- (0,0.5);
    \fill (0,0.5) circle [radius=1mm];
    \path[draw,fill=white,thick] (-0.3,0.10) arc[start angle=180,end angle=360,radius=3mm] -- cycle;
    \end{scope}
  }
}

\begin{tikzpicture}
  \draw[thick] (0,0)--(7,0) (0,1)--(7,1) (0,2)--(7,2)
               (1,-1)--(1,3) (3,-1)--(3,3) (6,-1)--(6,3);
  \draw (1,2) pic{element A}
        (1,1) pic{element A}
        (1,0) pic{element B};
  \draw (3,2) pic{element A}
        (3,1) pic{element B}
        (3,0) pic{element A};
  \draw (6,2) pic{element A}
        (6,1) pic{element B}
        (6,0) pic{element B};
\end{tikzpicture}


\end{document}
  • Thanks, with some small changes (scaled and with contact nodes of circuit ee IEC) exactly what I was looking for. – epR8GaYuh Jun 23 '16 at 11:33
1

My solution uses a semicircle shape for each cell which are distributed with a matrix of nodes.

Once semicircles are created, a foreach loop is used to add input connections and creates input nodes which will be later used for horizontal lines drawing.

Outputs are drawn in a similar way, a foreach loop where all connected cells are referenced.

Finally, horizontal and vertical lines are drawn with calc library help.

enter image description here

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{positioning,shapes.geometric,matrix,calc}

\begin{document}
\begin{tikzpicture}[
                  branch/.style={fill,shape=circle,minimum size=3pt,inner sep=0pt}
]

\matrix (mem) [matrix of nodes, row sep=5mm, column sep=8mm, nodes={draw, semicircle, rotate=-135,}, nodes in empty cells]
{&&[15mm]\\
&&\\&&\\};

\foreach \i in {1,2,3}{
    \foreach \j in {1,2,3}
        \draw (mem-\i-\j.chord center)--++(135:4mm) node (i-\i-\j) [circle, fill, minimum size=1mm, inner sep=0pt] {};
    \draw ([xshift=-5mm]i-\i-1.center)--([xshift=1cm]i-\i-3.center);
}
\foreach \i/\j in {1/1, 1/2, 1/3, 2/1, 3/2} 
        \draw (mem-\i-\j.apex)--++(-45:4mm) node (o-\i-\j) [circle, fill, minimum size=1mm, inner sep=0pt] {};

\foreach \j in {1,2,3}
    \draw ($(i-1-\j.center-|o-1-\j.center)+(0,5mm)$)--($(o-1-\j.center|-o-3-2.center)+(0,-5mm)$);
\end{tikzpicture}
\end{document}
1

Sort of does it. Possibly not ideal though. Uses a to path:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{shapes.geometric,arrows.meta}
\tikzset{
  connector/.tip={Circle[width=0.1cm,length=0.1cm]},
  every D/.style={
    semicircle, draw, minimum width=0.375cm, fill=white, rotate=90, inner sep=0,
  },
  *D*/.style={
    connector-connector,
    shorten >=-0.05cm, shorten <=-0.05cm,
    to path={
      (\tikztostart) -- node [midway, sloped, every D] {} (\tikztotarget)
    }
  },
  *D/.style={
    connector-,
    shorten >=-0.05cm, shorten <=-0.05cm,
    to path={
      (\tikztostart) -- node [at end, sloped, every D] {} (\tikztotarget)
    }
  },
}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) grid (2,2);
  \draw [*D*] (1/2,2) to (1,3/2);
  \draw [*D*] (3/2,2) to (2,3/2);
  \draw [*D]   (1/2,1) to ++(1/4,-1/4);
  \draw [*D]   (3/2,1) to ++(1/4,-1/4);
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.