# How to draw a quarter car model in LaTex? Which is basically a two masses and spring system

This is the code that i have been able to write up but i would like to make it better and label the springs and dampers and draw the ground. Also i need to draw the direction of the motion which would be y1 and y2 for two masses pointing up and i need to draw the free body diagram for this model. It would be really helpful if you can help me make this look good. I am having lot of trouble getting this done please help me.

    \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{dampener}=[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}
\node at (0,0) [draw,name=A,rectangle, minimum width=2cm,minimum height=1cm,anchor=south,,transform shape] {$m1$};
\node at (0,-2) [name=B,rectangle, minimum width=2cm,minimum height=1cm,anchor=north,,transform shape] {$m2$};
\draw [spring] (-0.5,-2) -- (-0.5,0) node[left] {k1};
\draw [dampener] (0.5,-2) -- (0.5,0);
%\node (ground1) at (-1,-5)  [ground, anchor=north] {};
\draw [ground] (-1,-5) -- (1,-5);
\draw [spring] (-0.5,-5) -- (-0.5,-3) ;
\draw [dampener] (0.5,-5) -- (0.5,-3);

\end{scope}
\end{tikzpicture}
\end{document}

• – Jake May 1 '12 at 5:45

I could not understand your question properly, especially the free body diagram part. However, will this be useful?

\documentclass{article}
\usepackage{graphicx} % to add figure environment that comes with caption
\usepackage{caption} %if you don't want to float your figure for using \captionof
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,circuits}
\begin{document}
Using \verb|graphicx| package:
\begin{figure}[htbp]
\centering
\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{dampener}=[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=4cm,minimum height=0.3cm]

\begin{scope}
\node at (0,0) [draw,rectangle, minimum width=2cm,minimum height=1cm,anchor=south,,transform shape](m1) {$m1$};
\draw [very thick, -latex](m1.north) -- +(0,1);
\node at (0,-2) [rectangle, minimum width=2cm,minimum height=1cm,anchor=north,,transform shape](m2) {$m2$};
\draw [very thick, -latex](m2.north) -- +(0,1);
\draw [spring] (-0.5,-2) -- (-0.5,0) node[midway,left=0.3cm] {k1};
\draw [dampener,label=D1,] (0.5,-2) -- (0.5,0)node[midway,right=0.4cm] {d1};
\node (ground1) at (0,-5)  [ground, anchor=north] {};
%        \draw [ground] (-1,-5) -- (1,-5);
\draw [spring] (-0.5,-5) -- (-0.5,-3)node[midway,left=0.3cm] {k2};
%     \draw [spring] (-0.5,-5) -- (-0.5,-3)node[draw=none,midway,left=0.3cm] {k2}; % If you don't want borders around lables use [draw=none]
\draw [dampener] (0.5,-5) -- (0.5,-3)node[midway,right=0.4cm] {d2};

\end{scope}
\end{tikzpicture}
\caption{My figure}\label{fig:myfigure1}
\end{figure}

Following will not float, we use \verb|\captionof| from \verb|caption| package. The package \verb|graphicx| not needed for this case.

\begingroup
\centering
\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{dampener}=[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=4cm,minimum height=0.3cm]

\begin{scope}
\node at (0,0) [draw,rectangle, minimum width=2cm,minimum height=1cm,anchor=south,,transform shape](m1) {$m1$};
\draw [very thick, -latex](m1.north) -- +(0,1);
\node at (0,-2) [rectangle, minimum width=2cm,minimum height=1cm,anchor=north,,transform shape](m2) {$m2$};
\draw [very thick, -latex](m2.north) -- +(0,1);
\draw [spring] (-0.5,-2) -- (-0.5,0) node[midway,left=0.3cm] {k1};
\draw [dampener,label=D1,] (0.5,-2) -- (0.5,0)node[midway,right=0.4cm] {d1};
\node (ground1) at (0,-5)  [ground, anchor=north] {};
%        \draw [ground] (-1,-5) -- (1,-5);
\draw [spring] (-0.5,-5) -- (-0.5,-3)node[midway,left=0.3cm] {k2};
%     \draw [spring] (-0.5,-5) -- (-0.5,-3)node[draw=none,midway,left=0.3cm] {k2}; % If you don't want borders around lables use [draw=none]
\draw [dampener] (0.5,-5) -- (0.5,-3)node[midway,right=0.4cm] {d2};

\end{scope}
\end{tikzpicture}
\captionof{figure}{My figure}\label{fig:myfigure2}
\endgroup
\end{document} • Thank You. Very much. I was going to draw a separate free body diagram but i think i can do that. Thank You for your help. – Hiren May 1 '12 at 2:13
• One last question how can add caption and Figure Number to this drawing. i tried using \caption{} command, but it didn't work. Thank You. – Hiren May 1 '12 at 2:26
• It is alright i figured it out. Thank You for helping out. – Hiren May 1 '12 at 2:29
• @Hiren: I have made the edit in case.... – user11232 May 1 '12 at 2:39