3

I dont get into the syntax of drawing a damper and a spring in row (without a mass or anything else between them): all i can do is draw them in parallel: another thing: how do I control the length of the spring?

Thank you a lot for you help!

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

\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=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]


\begin{scope}[xshift=7cm]

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


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


\draw [spring, width=15pt] (wall.170) -- ($(walle.south west)!(walle.170)!(walle.south east)$);
\draw [damper] (wall.10) -- ($(walle.south west)!(walle.10)!(walle.south east)$);

\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};



\end{scope}

\end{tikzpicture}

\end{document}

2 Answers 2

2

Like this?

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

\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=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]


\begin{scope}[xshift=7cm]

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


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


\draw [spring, line width=15pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(3.5cm,0)coordinate (m);
\draw [damper] (m) -- ($(walle.south west)!0.2!(walle.south east)$);

\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};

\end{scope}

\end{tikzpicture}

\end{document}

enter image description here

How to improve code?

First don't use \tikzstyle but tikzset. Instead of rotating individual nodes, forst draw them and rotate the entire piece. This makes you to visualise directions and anchors (like (wall.north east) etc) easier.

Further, you can set the length of spring by using relative coordinates like:

 \draw [spring, line width=15pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(0,3.5cm);

This means - "from a point at a distance of 0.2 of the total length from north west and north east (measured from north west)". -- ++(0,3.5cm) means - to a distance 0cm in x-direction and 3.5cm in y-direction".

Once the spring is drawn, we put a coordinate at the end of the spring

............++(0,3.5cm)coordinate (m);

From (m) we draw the damper to walle:

\draw [damper] (m) -- ($(walle.south west)!0.2!(walle.south east)$);

where the second part is as explained before.

Full code:

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

\begin{document}

\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick}]
\tikzset{
    spring/.style = {thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment 
                        length=6}},
    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=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},
    ground/.style ={fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm}
}

\begin{scope}[rotate=-90,transform shape]       %%% rotate here, both options needed.

\node (wall) [ground, minimum width=3cm,anchor=center] at (0,0) {};
\node (walle) [ground, minimum width=3cm,anchor=center] at (0,6) {};


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


\draw [spring, line width=15pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(0,3.5cm)coordinate (m);
\draw [damper] (m) -- ($(walle.south west)!0.2!(walle.south east)$);
 %
%% now a parallel spring
\draw [spring, line width=15pt] ($(wall.north west)!0.8!(wall.north east)$) -- ($(walle.south west)!0.8!(walle.south east)$);

%\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};

\end{scope}

\end{tikzpicture}

\end{document}

The result is:

enter image description here

1

Thanks a very lot!! enter image description here Here's my final code for all beeing interested:

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

\begin{document}

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

\begin{scope}[rotate=-90,transform shape]       %%% rotate here, both options needed.

\node (wall) [ground, minimum width=3cm,anchor=center] at (0,0) {};
\node (walle) [ground, minimum width=3cm,anchor=center] at (0,6) {};

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

%% now a parallel spring
\draw [line width=0.8pt] ($(wall.north west)!0.2!(wall.north east)$) -- ++(0,2cm)coordinate (z);
\draw [spring] (z) -- ++(0,2cm)coordinate (t); 
\draw [line width=0.8pt] (t) -- ($(walle.south west)!0.2!(walle.south east)$);

\end{scope}


\begin{scope}[rotate=-90,transform shape]       %%% rotate here, both options needed.

\draw [line width=0.8pt] ($(wall.north west)!0.8!(wall.north east)$) -- ++(0,1cm)coordinate (z);
\draw [spring] (z) -- ++(0,2cm)coordinate (t); 
\draw [damper] (t) -- ++(0,2cm)coordinate (u); 
\draw [line width=0.8pt] (u) -- ($(walle.south west)!0.8!(walle.south east)$);

\end{scope}

\end{tikzpicture}

\end{document}
1
  • Why you are using two scopes? Only one is enough. Comment lines 38 and 41.
    – user11232
    Feb 4, 2014 at 23:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .