11

This is my code:

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

\begin{document}
\tikzset{spring/.style={thick,decorate,decoration={zigzag,pre
length=0.3cm,post length=0.3cm,segment length=6}}, short
spring/.style={thick,decorate,decoration={zigzag,pre
length=0.05cm,post length=0.05cm,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},
ground_magenta/.style={fill,pattern=north east lines,pattern
color=magenta,draw=none,minimum width=0.75cm,minimum height=0.3cm}}

\begin{tikzpicture}[every node/.style={draw,outer
sep=0pt,thick},font=\sffamily]

\node (m_1) [minimum width=1cm,minimum
height=0.5cm]{$m_1$}; \node (m_2)[right of= m_1,node
distance=2.5cm,minimum width=1cm,minimum height=0.5cm]{$m_2$}; \draw
[spring] (m_1.east) -- (m_2.west)
node[midway,below=1mm,draw=none]{$k_{12}$}; \node (ground1) at
(m_1.south west)
 [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {}; \draw
(ground1.south west) -- (ground1.south east); 


\end{document}

How to draw the L Shaped spring in the picture below?

enter image description here

13

Method 1

Here is a way to do it using -| which draws a right angle between the two points (ground1.south) and (m_1.south).

But, it requires you to manually adjust the pre length and post length of the spring so that it fits nicely in the horizontal segment of the line. Also some adjustment to the position of the label is required.

enter image description here

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

\begin{document}
\tikzset{spring/.style={thick,decorate,decoration={zigzag,pre
length=0.3cm,post length=0.3cm,segment length=6}}, short
spring/.style={thick,decorate,decoration={zigzag,pre
length=0.05cm,post length=0.05cm,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},
ground_magenta/.style={fill,pattern=north east lines,pattern
color=magenta,draw=none,minimum width=0.75cm,minimum height=0.3cm}}

\begin{tikzpicture}[every node/.style={draw,outer
sep=0pt,thick},font=\sffamily]

\node (m_1) [minimum width=1cm,minimum height=0.5cm]{$m_1$}; 
\node (m_2)[right of= m_1,node distance=2.5cm,minimum width=1cm,minimum height=0.5cm]{$m_2$}; 
\draw [spring] (m_1.east) -- (m_2.west) node[midway,below=1mm,draw=none]{$k_{12}$}; 
\node (ground1) at (m_1.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {}; 
 \draw (ground1.south west) -- (ground1.south east); 
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground1.south) -| (m_1.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g1}$} ;

\end{tikzpicture}
\end{document}

Method 2

Another method could be to draw the two lines separately. This potentially allows you better control over the spring, as it is just specified for the horizontal segment (therefore you can set the same post and pre lengths). And the label is nicely centred underneath it.

UPDATE: thanks to @richardneish for pointing out line cap=rect fixes the gap at the intersection point.

enter image description here

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

\begin{document}
\tikzset{spring/.style={thick,decorate,decoration={zigzag,pre
length=0.3cm,post length=0.3cm,segment length=6}}, short
spring/.style={thick,decorate,decoration={zigzag,pre
length=0.07cm,post length=0.07cm,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},
ground_magenta/.style={fill,pattern=north east lines,pattern
color=magenta,draw=none,minimum width=0.75cm,minimum height=0.3cm}}

\begin{tikzpicture}[every node/.style={draw,outer
sep=0pt,thick},font=\sffamily]

\node (m_1) [minimum width=1cm,minimum height=0.5cm]{$m_1$}; 
\node (m_2)[right of= m_1,node distance=2.5cm,minimum width=1cm,minimum height=0.5cm]{$m_2$}; 
\draw [spring] (m_1.east) -- (m_2.west) node[midway,below=1mm,draw=none]{$k_{12}$}; 
\node (ground1) at (m_1.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {}; 
 \draw (ground1.south west) -- (ground1.south east); 

\path (ground1.south) -| coordinate (midpoint) (m_1.south);
\draw [short spring] (ground1.south) -- (midpoint) node [midway, below=1mm,draw=none] {$k_{g1}$};
\draw [thick, line cap=rect] (midpoint)--(m_1.south);

\end{tikzpicture}
\end{document}
  • 2
    Wouldn't adding line cap=rect fix the small break between the two lines at the intersection point? – richardneish Oct 29 '18 at 15:28

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.