1

Related to the question Drawing a system of pendulums I tried to draw the case when the bobs are in opposite phases (the last figure in the output), by mimicking the stretch of the spring.

The code is:

\documentclass{article}
\usepackage{tikz}

\usepackage{tikz} \usetikzlibrary{ angles, quotes, arrows.meta, decorations.markings, decorations.pathmorphing, decorations.pathreplacing, calc, patterns, positioning } \tikzset{ spring/.style={thick,decorate,decoration={aspect=0.5, segment length=#1, amplitude=3mm,zigzag}}, springgg/.style={thick,decorate,decoration={aspect=0.5, segment length=#1, amplitude=2mm,zigzag}}, blank/.style={draw=none,fill=none,pos=0.5}, ground/.style={fill,pattern=north east lines,draw=none,minimum width=0.5cm,minimum height=0.3cm}, damper/.style={thick, decoration={markings, mark connection node=dmp, mark=at position 0.5 with { \node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=10pt,minimum height=3pt,draw=none] {}; \draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$); \draw [thick] ($(dmp.north)+(0,-3pt)$) -- ($(dmp.north)+(0,3pt)$); } }, decorate }, box/.style={draw,thick,minimum width=1cm, minimum height=1cm}, dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}, extended line/.style={shorten >=-#1,shorten <=-#1}, extended line/.default=0cm, bob/.style={draw,fill=gray!40,circle,minimum size=6pt,inner sep=6pt} }

\begin{document}

\begin{figure}[htbp] \centering \begin{tikzpicture}

\begin{scope} \node (wall) [ground, minimum width=4cm] {}; \draw (wall.south east) -- (wall.south west);

\coordinate (pivot1) at (-1,-0.16);
\draw[thick,-] (pivot1) -- ++ (0,-4)
  node (bob1) [bob]{$$}
  coordinate [midway] (resort1);

\coordinate (pivot2) at (1,-0.16);
\draw[thick,-] (pivot2) -- ++ (0,-4)
  node (bob2) [bob]{$$}
  coordinate [midway] (resort2);

\coordinate (topspring) at ($(resort1) + (0.2cm,0)$); \coordinate (bottomspring) at ($(resort2) - (0.2cm,0)$);

\draw [decoration={aspect=0.3, pre length=0.3cm, post length=0.3cm, segment length=3mm, amplitude=3mm,zigzag},thick,decorate] (resort1)--(resort2);

\draw[decorate,decoration={brace,amplitude=.35cm}] (pivot2) -- node[right=3mm] {$l$} (resort2); \draw[decorate,decoration={brace,mirror,amplitude=.35cm}] (pivot1) to node[left=3mm] {$L$} (bob1); \end{scope}

\begin{scope}[xshift=4.5cm] \node (wall) [ground, minimum width=4cm] {}; \draw (wall.south east) -- (wall.south west);

\useasboundingbox (wall.north west) rectangle ([yshift=-4cm]wall.east);

\pgfmathsetmacro{\myAngle}{30}

\coordinate (pivot1) at (-1,-0.16);
\draw[thick] (pivot1) -- ++ (270+\myAngle:4cm)
  node (bob1) [bob]{$$}
  coordinate [midway] (spring1);

\coordinate (c1) at (pivot1|-spring1);

\pic [draw, -,font=\small,&quot;$\theta_1$&quot;, angle eccentricity=1.5] {angle = c1--pivot1--bob1};

\coordinate (pivot2) at (1,-0.16);
\draw[thick] (pivot2) -- ++(270+\myAngle:4cm)
  node (bob2) [bob]{$$}
  coordinate [midway] (spring2);
\coordinate (c2) at (pivot2|-spring2);

\pic [draw, font=\small, &quot;$\theta_2$&quot;, angle eccentricity=1.5] {angle = c2--pivot2--bob2};

\coordinate (topspring) at ($(spring1) + (0.2cm,0)$); \coordinate (bottomspring) at ($(spring2) - (0.2cm,0)$);

\draw [decoration={aspect=0.3, pre length=0.3cm, post length=0.3cm, segment length=3mm, amplitude=3mm,zigzag},thick,decorate] (spring1)--(spring2);

\draw [thick, densely dotted] (pivot1) |- (spring1);
\draw [thick, densely dotted] (pivot2) |- (spring2);

\draw[decorate,decoration={brace,mirror,amplitude=.25cm}] (c1) -- node[below=2mm] {$x$} (spring1);
\draw[decorate,decoration={brace,mirror,amplitude=.25cm}] (c2) -- node[below=2mm] {$y$} (spring2);

\draw[decorate,decoration={brace,amplitude=.35cm}] (pivot1) -- node[blank,right=3mm,yshift=2mm] {$l$} (spring1);
\draw[decorate,decoration={brace,amplitude=.35cm}] (pivot2) -- node[blank,right=3mm,yshift=2mm] {$L$}(bob2) ;

\end{scope} \end{tikzpicture} \end{figure}

\begin{figure}[htbp] \centering \begin{tikzpicture}

\node (wall) [ground, minimum width=4cm] {}; \draw (wall.south east) -- (wall.south west);

\pgfmathsetmacro{\myAngle}{30}

\coordinate (pivot1) at (-1,-0.16); \draw[thick] (pivot1) -- ++ (270+\myAngle-60:4cm) node (bob1) [bob]{$$} coordinate [midway] (arc1);

\coordinate (c1) at (pivot1|-arc1);

\pic [draw, -,font=\small,&quot;$\theta_1$&quot;, angle eccentricity=1.5] {angle = bob1--pivot1--c1};

\coordinate (pivot2) at (1,-0.16);
\draw[thick] (pivot2) -- ++(270+\myAngle:4cm)
  node (bob2) [bob]{$$}
  coordinate [midway] (arc2);
\coordinate (c2) at (pivot2|-arc2);

\pic [draw, font=\small, &quot;$\theta_2$&quot;, angle eccentricity=1.5] {angle = c2--pivot2--bob2};

\draw [decoration={aspect=0.3, pre length=0.3cm, post length=0.3cm, segment length=7mm, amplitude=2mm,zigzag},thick,decorate] (arc1)--(arc2);

\draw [thick, densely dotted] (pivot1) |- (arc1); \draw [thick, densely dotted] (pivot2) |- (arc2);

\draw[decorate,decoration={brace,amplitude=.25cm}] (c1) -- node[below=2mm] {$x$} (arc1); \draw[decorate,decoration={brace,mirror,amplitude=.25cm}] (c2) -- node[below=2mm] {$y$} (arc2); \draw[decorate,decoration={brace,mirror,amplitude=.35cm}] (pivot1) -- node[blank,left=3mm,yshift=2mm] {$l$} (arc1); \draw[decorate,decoration={brace,amplitude=.35cm}] (pivot2) -- node[blank,right=3mm,yshift=2mm] {$L$}(bob2);

\end{tikzpicture} \end{figure} \end{document}

with the output: enter image description here

Th problem is that the lengths of the segments connecting the left-right ends of the springs to the points where the springs are attached to the strings are different, even if the pre length and post length in the definition of the springs are both equal to 0.3cm.

How could I make these segments of equal lengths ?

Cris
  • 1,189

1 Answers1

2

It seems that what happens is that if the available distance for the zigzags is not exactly some integer multiple of half the segment length, the post length is extended to fit the remaining space. If you for example change the segment length to 6mm instead of 7mm, it looks better.

However, it is possible to calculate an appropriate segment length, using the let .. in syntax of the calc library (see section 14.15 The Let Operation in the TikZ manual):

   \draw 
     let 
      \p1=(arc1),\p2=(arc2), % now \x1 is the x-coord of arc1 and \x2 that of arc2
      \n1={veclen(\x2-\x1,\y2-\y1)-2*0.3cm}, % calculate distance available for the zigzags
      \n2={\n1/5.5} % calculate the segment lengths, distance available over number of zigzags (here 5.5)
      in
   [decoration={pre length=0.3cm, post length=0.3cm, segment length=\n2, amplitude=2mm,zigzag},thick,decorate] (arc1)--(arc2);

There might well be more elegant ways of achieving this as well, but this one should work. (For this case you could calculate \n1 as \x2-\x1-2*0.3cm, the veclen approach works for non-horizontal springs as well.)

Put into a somewhat more concise complete example, where the red lines with | arrow tips indicate a distance of 0.3cm from arc1 and arc2. And by the way, I don't think the aspect option does anything for a zigzag decoration, so you can actually remove that.

enter image description here

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
   decorations.pathmorphing,
   calc,
   }
\begin{document}
\begin{tikzpicture}

\pgfmathsetmacro{\myAngle}{30}

\coordinate (pivot1) at (-1,-0.16); \draw[thick] (pivot1) -- ++ (270+\myAngle-60:4cm) coordinate [midway] (arc1);

\coordinate (pivot2) at (1,-0.16); \draw[thick] (pivot2) -- ++(270+\myAngle:4cm) coordinate [midway] (arc2);

\draw let \p1=(arc1),\p2=(arc2), % now \x1 is the x-coord of arc1 and \x2 that of arc2 \n1={veclen(\x2-\x1,\y2-\y1)-2*0.3cm}, % calculate distance available for the zigzags \n2={\n1/5.5} % calculate the segment lengths, distance available over number of zigzags (here 5.5) in [decoration={pre length=0.3cm, post length=0.3cm, segment length=\n2, amplitude=2mm,zigzag},thick,decorate] (arc1)--(arc2);

% the following two lines just to indicate that the post and pre length are the same \draw [red,thick, -|] (arc1) -- +(0.3cm,0); \draw [red,thick, -|] (arc2) -- +(-0.3cm,0); \end{tikzpicture} \end{document}

Torbjørn T.
  • 206,688
  • Thank you so much for this very elegant approach! I had no idea about the 'let' operation and I will try to use it from now on. Indeed, the 'aspect' option doesn't change anything for 'zigzag' and I removed it. – Cris Jul 05 '20 at 15:01