9

I found this question, A Mechanical System in Tikz, wich I found to be very useful for drawing diagrams, I am trying to recreate this drawing I made using IPE (my drawing is not nice at all).

IPE diagram

I already did the easy part but I am having problems placing parallel elements (the spring and the damper).

I understand that \draw [damper] (ground.south) -- (M.north); means "Wich element you want to draw, from.position, to.position" but I dont understand the coordinate system in \draw [damper] (M.0) -- (M2.0); or \draw [damper] (wall.75) -- ($(M.north west)!(wall.75)!(M.south west)$); (The last code can be found in the question link). I would be glad if someone could explain that to me, this is my code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
        \tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
        \tikzstyle{damper}=[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=15pt,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,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
            }
        }, decorate]
        \tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm,inner sep=0pt,outer sep=0pt]

        \node [draw, outer sep=0pt, thick] (M) [minimum width=2cm, minimum height=1cm] {$m_1$};
        \node [draw, outer sep=0pt, thick] (M2) [minimum width=2cm, minimum height=1cm, yshift =-2cm] {$m_2$};

        \node (ground) [ground,anchor=north,yshift=1cm,minimum width=4cm,xshift=0cm] at (M.north) {};
        \draw (ground.north east) -- (ground.north west);
        \draw (ground.south east) -- (ground.south west);
        \draw (ground.north east) -- (ground.south east);
        \draw (ground.north west) -- (ground.south west);

        \draw [damper] (ground.south) -- (M.north);
        \draw [spring] (ground.0) -- (M.0);
        \draw [spring] (M.south) -- (M2.north);
        \draw [damper] (M.0) -- (M2.0);

        \draw [-latex,ultra thick] (M2.south) ++ (0cm,0cm) -- +(0cm,-1cm);
        \node (z) at (M2.south) [yshift = -1cm] {$z$};
        \end{tikzpicture}
    \end{center}
\end{document}

And this is my output

Tikz diagram


Thanks to user @marsupilam wich handed me a link in wich I learned how the coordinate system work (that argument was an angle!) I finally reproduced the drawing:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
        \tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
        \tikzstyle{damper}=[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=15pt,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,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
            }
        }, decorate]
        \tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm,inner sep=0pt,outer sep=0pt]

        \node [draw, outer sep=0pt, thick] (M) [minimum width=2cm, minimum height=1cm] {$m_1$};
        \node [draw, outer sep=0pt, thick] (M2) [minimum width=2cm, minimum height=1cm, yshift =-2cm] {$m_2$};

        \node (ground) [ground,anchor=north,yshift=1.2cm,minimum width=4cm,xshift=0cm] at (M.north) {};
        \draw (ground.north east) -- (ground.north west);
        \draw (ground.south east) -- (ground.south west);
        \draw (ground.north east) -- (ground.south east);
        \draw (ground.north west) -- (ground.south west);

        \draw [spring] (ground.194) -- ($(M.north west)!(ground.194)!(M.north east)$);
        \draw [damper] (ground.346) -- ($(M.north west)!(ground.346)!(M.north east)$);
        \draw [damper] (M.220) -- ($(M2.north west)!(M.220)!(M2.north east)$);
        \draw [spring] (M.320) -- ($(M2.north west)!(M.320)!(M2.north east)$);

        \draw [-latex,ultra thick] (M2.south) ++ (0cm,0cm) -- +(0cm,-1cm);
        \node (ft) at (M2.south) [yshift = -1cm] {$f(t)$};
        \node (b2) at (M2.north) [xshift = -1.2cm, yshift = 0.5cm] {$b_2$};
        \node (k1) at (M.north) [xshift = -1.2cm, yshift = 0.5cm] {$k_1$};
        \node (k2) at (M2.north) [xshift = 1.2cm, yshift = 0.5cm] {$k_2$};
        \node (b1) at (M.north) [xshift = 1.2cm, yshift = 0.5cm] {$b_1$};
        \end{tikzpicture}
    \end{center}
\end{document}

The output:

diagram 2

Note: I actually had to do trial and error to vertical align the elements, the angular coordinate changes with the width and height of the ground or mass, probably there is an automatic way to vertical align the springs and dampers.

  • 1
    Your question for the syntax (A.angle) is explained here by Caramdir – marsupilam Apr 1 '17 at 18:16
  • @marsupilam Thank you very much, that's the information I nedeed, now I finally reproduced the first drawing, please write your comment as an answer to close this. I will update my question with the final MWE. – Paul Lara Apr 1 '17 at 19:08
  • @Paul Lara If all you needed was this tiny pointer, I think you may answer your own question yourself, and close thusly. – marsupilam Apr 1 '17 at 19:11
6

Nodes anchors : node.〈angle〉, angle between 0 (=east) and 360, measured counterclockwise.

I added a new element(not drawing) as a duplicat of ground(=>ground2) for correct positioning, because of different widths of the elemens ground,m1,m2. So you can set the same angles for the different nodes.

enter image description here

MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}

\begin{document}
\begin{center}
    \begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
    \tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
    \tikzstyle{damper}=[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=15pt,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,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
        }
    }, decorate]
    \tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm,inner sep=0pt,outer sep=0pt]

    \node [draw, outer sep=0pt, thick] (M) [minimum width=2cm, minimum height=1cm] {$m_1$};
    \node [draw, outer sep=0pt, thick] (M2) [minimum width=2cm, minimum height=1cm, yshift =-2cm] {$m_2$};

    \node (ground) [anchor=north,ground,yshift=1.3cm,minimum width=4cm,xshift=0cm] at (M.north) {};

     \node [outer sep=0pt, thick] (ground2) [minimum width=2cm, minimum height=1cm, yshift =2cm] {};

    \draw (ground.south east) -- (ground.south west);

    \draw [damper] (M.40) -- (ground2.-40) node [midway,right,xshift=0.3cm] {$b_1$};
    \draw [spring] (ground2.-140) -- (M.140) node [midway,left] {$k_1$};

    \draw [spring] (M.-40) -- (M2.40)node [midway,right] {$k_2$};
    \draw [damper](M2.140) -- (M.-140) node [midway,left,xshift=-0.3cm] {$b_2$};

    \draw [-latex,ultra thick] (M2.south) ++ (0cm,0cm) -- +(0cm,-1cm);
    \node (z) at (M2.south) [yshift = -1cm] {$f(t)$};

    \end{tikzpicture}
\end{center}
\end{document}
  • Your solution to the problem with the angles is brilliant – Paul Lara Apr 5 '17 at 2:10
7

Like this?

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{calc, decorations.pathmorphing, decorations.markings,
                 patterns, positioning}

\begin{document}
    \begin{tikzpicture}[semithick,
node distance = 14mm and 7mm,
spring/.style = {decorate,
                 decoration={zigzag, pre length=0.3cm, post length=0.3cm, segment length=6pt},
                 },
damper/.style = {decoration={markings, mark connection node=dmp, mark=at position 0.5 with
            {
                \node (dmp) [minimum width=15pt, minimum height=3pt, inner sep=0pt] {};
                \draw (dmp.north west) -| 
                      (dmp.south east) -- (dmp.north east);
                \draw[very thick] ($(dmp.north west)+(0.6pt, 2pt)$) --
                                  ($(dmp.north east)+(0.6pt,-2pt)$);
            }
                                }, decorate},
ground/.style = {pattern=north east lines, 
                 minimum width=3cm, minimum height=0.3cm, inner sep=0pt, outer sep=0pt},
  mass/.style = {draw, minimum width=2cm, minimum height=1cm, outer sep=0pt}             
                 ]
%
\node (G)   [ground] {};
    \draw (G.south east) -- (G.south west);
\node (M1)  [mass,below=of G]   {$m_1$};
\node (M2)  [mass,below=of M1]  {$m_2$};
% auxilary coordinates 
\coordinate[left =of G.south] (G1);
\coordinate[right=of G.south] (G2);
% springs
\draw[spring]   (G1)             -- node[left ] {$k_1$} (M1.north -| G1);
\draw[spring]   (G2 |- M1.south) -- node[right] {$k_2$} (M2.north -| G2);
% dampers
\draw [damper]  (G2)             -- node[right=2mm] {$b_1$} (M1.north -| G2);
\draw [damper]  (M1.south -| G1) -- node[left =2mm] {$b_2$} (M2.north -| G1);
% force
\draw[-latex,ultra thick] (M2.south) -- +(0cm,-1cm) node[below] {$f(t)$};
    \end{tikzpicture}
\end{document}

I simplify your code as much as I know. In this I follow to the first image in your question. For positioning of damper and spring I define two auxiliary coordinates (G1 and G) where start spring k1 and dumper b1 and finished at G1 |- M1.north and M1.north -| G2. Similarly are determined start and end points for spring k2 and dumper b2.

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.