1

I am sorry for previous problem, I am new on this useful forum and I still need help.

I have written the following code, in order to draw 2 coupled horizontal oscillators with dampers:

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

\begin{document}

\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\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=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]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.5cm,minimum height=0.3cm]

\begin{scope}[xshift=7cm]
\node (M) [minimum width=1cm, minimum height=1cm] {$m$} node[draw=none,fill=none,pos=.5,below] {1};

\draw [<-,thick](-2.6,.6) -- (-1.5,-.2);

\node (wall) [ground, rotate=-90, minimum width=2cm,yshift=-3cm] {};

\draw (wall.north east) -- (wall.north west);

\draw [spring] (wall.120) -- ($(M.north west)!(wall.120)!(M.south west)$) node[draw=none,fill=none,pos=.5,above] {$k_1$};

\draw [damper] (wall.20) -- ($(M.north west)!(wall.20)!(M.south west)$) node[draw=none,fill=none,pos=.5,below] {$d_1$};
\end{scope}

\begin{scope}[xshift=10cm]
\node (M1) [minimum width=1cm, minimum height=1cm] {$m$} node[draw=none,fill=none,pos=.5,below] {2};

\draw [spring] (M.10) -- ($(M1.north west)!(M.10)!(M1.south west)$) node[draw=none,fill=none,pos=.5,above] {$K$};

\draw [damper] (M.-40) -- ($(M1.north west)!(M.-40)!(M1.south west)$);

\draw [->,thick](1.4,-.2) -- (2.5,.6);
\end{scope}

\begin{scope}[xshift=10cm]
\node (wall1) [ground, rotate=90, minimum width=2cm,yshift=-3cm] {};

\draw (wall1.north west) -- (wall1.north east);

\draw [spring] (wall1.60) -- ($(M1.north east)!(wall1.60)!(M1.south east)$) node[draw=none,fill=none,pos=.5,above] {$k_2$};

\draw [damper] (wall1.-160) -- ($(M1.north east)!(wall1.-160)!(M1.south east)$) node[draw=none,fill=none,pos=.5,below] {$d_2$};
\end{scope}

\end{tikzpicture}

\end{document}

enter image description here

I need help to fix the following issues:

  1. The notations "d_1" and "d_2" of the two dampers should be placed with about 3mm, under the dampers.
  2. The notations "1" and "2" of the two blocks should be placed under the rectangles and not at the interior.
  3. The right-side point of the second damper should start from the vertical rule of the right wall, not from those north east lines.
2

Points one and two are easily fixed as you can write below=<distance> and for point 3 you just need to draw the line from (wall1.160) instead of (wall1.-160).

You can also rationalise your code a little by putting all of the style commands inside a \tikzset{...} at the top (see Should \tikzset or \tikzstyle be used to define TikZ styles?) and giving a name, I have used blank to the often used style draw=none,fill=none,pos=.5.

enter image description here

Here's the full code:

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

    \begin{document}

    \tikzset{
      spring/.style={thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}},
      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
      }
    }

    \begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
      \begin{scope}[xshift=7cm]
        \node (M) [minimum width=1cm, minimum height=1cm] {$m$} node[blank,below=0.7] {1};
        \draw [<-,thick](-2.6,.6) -- (-1.5,-.2);
        \node (wall) [ground, rotate=-90, minimum width=2cm,yshift=-3cm] {};
        \draw (wall.north east) -- (wall.north west);
        \draw [spring] (wall.120) -- ($(M.north west)!(wall.120)!(M.south west)$) node[blank,above] {$k_1$};
    \draw [damper] (wall.20) -- ($(M.north west)!(wall.20)!(M.south west)$) node[blank,below=0.2] {$d_1$};
  \end{scope}
  \begin{scope}[xshift=10cm]
    \node (M1) [minimum width=1cm, minimum height=1cm] {$m$} node[blank,below=0.7] {2};
    \draw [spring] (M.10) -- ($(M1.north west)!(M.10)!(M1.south west)$) node[blank,above] {$K$};
    \draw [damper] (M.-40) -- ($(M1.north west)!(M.-40)!(M1.south west)$);
    \draw [->,thick](1.4,-.2) -- (2.5,.6);
  \end{scope}
  \begin{scope}[xshift=10cm]
    \node[] (wall1) [ground, rotate=90, minimum width=2cm,yshift=-3cm] {};
    \draw (wall1.north west) -- (wall1.north east);
    \draw [spring] (wall1.60) -- ($(M1.north east)!(wall1.60)!(M1.south east)$) node[blank,above] {$k_2$};
    \draw [damper] (wall1.160) -- ($(M1.north east)!(wall1.-160)!(M1.south east)$) node[blank,below=0.2] {$d_2$};
  \end{scope}
\end{tikzpicture}

\end{document}
0
1

Replace this

node[draw=none,fill=none,pos=.5,below] {$d_2$};

with

node[draw=none,fill=none,pos=.5,below,yshift=-2mm] {$d_2$};

and this

node[draw=none,fill=none,pos=.5,below] {$d_1$};

with

node[draw=none,fill=none,pos=.5,below,yshift=-2mm] {$d_1$};

and this

\draw [damper] (wall1.-160) -- ($(M1.north east)!(wall1.-160)!(M1.south east)$)

with this

\draw [damper] (wall1.160) -- ($(M1.north east)!(wall1.-160)!(M1.south east)$)

2
  • I'm not Andrew but I hope the message conveyed :)
    – CroCo
    Nov 4 '17 at 16:12
  • I am sorry, I've just seen Andrew. Thank you a lot, CroCo !
    – Cris
    Nov 4 '17 at 16:22

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.