0

I am sorry for the previous problem, I am a beginner of this forum.

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 would 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.
3
\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}[
  wall/.style = {gray,fill=gray},
  mass/.style = {draw,circle,ball color=red},
  spring/.style = {decorate,decoration={zigzag, pre length=.3cm,post length=.3cm,segment length=#1}},
  ]
  \draw[wall] (-.5,-1) rectangle (0,1);
  \coordinate (l) at (0,0);
  \node[mass,label={above:$m_1$}] (m1) at (3,0) {};
  \node[mass,label={above:$m_2$}] (m2) at (5,0) {};
  \coordinate (r) at (6,0);
  \draw[wall] (6,-1) rectangle (6.5,1);

  \draw[spring=8pt] (l) -- node[above] {$k_1$} (m1);
  \draw[spring=4pt] (m1) -- node[above] {$K$} (m2);
  \draw[spring=2pt] (m2) -- node[above] {$k_2$} (r);
\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.