6

I have a drawing of a curved-plate capacitor:

\documentclass[]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}[
    baseline=(current bounding box.center), 
    capacitor/.style = {
        line width=2mm,
        color=black,
    },
    cable/.style = {
        very thick,
        color=black,
        -o,
    },
    ]  
    % 
    \def\upper{(1,4) to[out=-30,in=210] (9,4)}
    \def\lower{(1,1) -- (9,1)}
    \draw [thick, gray] \lower;
    \draw [thick, gray, name path=membrane] \upper;
    % invisible paths for intersections 
    \path [name path=verticalout] (7,0) -- (7,5);
    % upper plate of the capacitor on the bended membrane
    \begin{scope}
        \clip (2.45,-1) rectangle (7.55,5.5);
        \draw [capacitor] \upper;
        \draw [capacitor] \lower;
        \foreach \i in {2,3,...,8} {
            \path[yshift=-4mm] (1,4) to[out=-30,in=210]  node[red, pos=0.\i]{$+$} (9,4);
            \path[yshift=4mm] (1,1) -- node[blue, pos=0.\i]{$-$} (9,1);
        }
    \end{scope}
    % cables out
    \draw [cable, name intersections={of=membrane and verticalout}] 
          (intersection-1) |- (11,5); 
    \draw [cable] (7,1) |- (11,-0.5);
\end{tikzpicture}
\end{document}

curved capacitor

Although I am quite satisfied with the resulting figure, I think that the foreach part I used to put the red pluses and the blue minuses is quite hacky:

  1. I can't use the macro \upper and \lower there (I have to split the path building expression);

  2. I am not sure that the vertical alignment is guaranteed if I change the \upper or \lower path

  3. I tried to do it with text decorations, but failed in three things:

    • I have to use a string like $+ + + +$ because I could not find how to "repeat" a single char

    • The symbols got rotated along the path

    • I gave up trying to align the upper "+" with the lower "-"...

Is there a generic way to put a series of repeated symbols along a path?

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • 1
    Have you looked at the decorations.text library? Probably you want text effects along path although text along path might be OK. – cfr May 07 '15 at 12:44
  • Will you be happy with this? \def\upper{(1,4) to[out=-30,in=210] node foreach \i in {2,3,...,8}[yshift=-4mm,red, pos=0.\i] {$+$} (9,4)} \def\lower{(1,1) -- node foreach \i in {2,3,...,8}[yshift=4mm,blue, pos=0.\i] {$-$} (9,1)} –  May 07 '15 at 14:14
  • ...@HarishKumar --- and this shows how much time passed since I used plain TeX... I did not suspect I could put a foreach into a path... thanks. – Rmano May 07 '15 at 14:38
  • @Rmano Could you add a generic answer to remove it from unanswered queue – percusse Jun 02 '18 at 11:05
  • 1
    @percusse, done! – Rmano Jun 02 '18 at 16:28

1 Answers1

3

In the end, I adopted the following code:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{intersections}
\usetikzlibrary{patterns}
\usetikzlibrary{shadows}
\begin{document}

\begin{tikzpicture}[
    baseline=(current bounding box.center), 
    scale=0.5, 
    every node/.style={transform shape}, %% to apply scale to nodes
    capacitor/.style = {
        line width=2mm,
        color=black,
    },
    cable/.style = {
        very thick,
        color=black,
        -o,
    },
    ]  
    % internal chamber
    \path [fill=gray!20] (1,4) to[out=-30,in=210] (9,4) -- 
          node [left, pos=0.7]{\Large $P_0=1$~atm}  
    (9,1) -- (1, 1) -- cycle;
    % structure 
    \draw [pattern=north east lines, pattern color=gray] 
          (0,0) -- (0,4) -- (1,4) -- (1,1) -- 
          (9,1) -- (9,4) -- (10,4) -- (10,0) -- cycle;
    \draw [thick, name path=membrane] (1,4) to[out=-30,in=210] (9,4);
    % invisible paths for intersections 
    \path [name path=vertical1] (2,0) -- (2,5);
    \path [name path=vertical2] (7,0) -- (7,5);
    % big arrow with $P$ into it 
    \path [fill=gray!40, drop shadow ] (4, 6) -- (4,4) -- (3.5, 4) -- 
          (5,3) -- (6.5, 4) -- (6,4) -- (6, 6);
    \path (5,4) node {\Huge $P$};
    \path (2,5.5) node [align=left] (mtext) 
          {\Large Elastic \\ \Large membrane};
    \draw [name intersections={of=membrane and vertical1}] 
          (mtext.south) edge[bend left, ->, shorten >=2pt] (intersection-1);
    % upper plate of the capacitor on the bended membrane
    \begin{scope}
        \clip (2.45,-1) rectangle (7.55,5.5);
        \draw [capacitor] (1,4) to[out=-30,in=210] (9,4);
        %% pluses and minuses
        \foreach \i in {2,3,...,8} {
            \path[yshift=-4mm] 
                 (1,4) to[out=-30,in=210]  node[red, pos=0.\i]{$+$} (9,4);
            \path[yshift=4mm] 
                 (1,1) -- node[blue, pos=0.\i]{$-$} (9,1);
        }
    \end{scope}
    % lower plate of the capacitor
    \draw [capacitor] (2.5,1) -- (7.5,1);
    \draw [cable, name intersections={of=membrane and vertical2}] 
          (intersection-1) |- (11,5); 
    \draw [cable] (7,1) |- (11,-0.5);
\end{tikzpicture}

\end{document}

fake capacitive pressure sensor

Rmano
  • 40,848
  • 3
  • 64
  • 125