[Tex/LaTex] There is a more compact way for drawing this quarter-car model

technical-drawingtikz-pgf

I have written this code:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\begin{tikzpicture}

    % Sprung mass
    \shade[top color=gray, bottom color=white, shading angle={135}]
        [draw=black,fill=gray!20,rounded corners=1.2ex,very thick] (1.5,.5) rectangle (6.5,2.5);
    \draw (10,1.5) node {Sprung mass};      
    \draw (4,1.5) node {$M$};

    \draw[->,very thick] (1.5,1.5) -- (0,1.5) -- (0,0);
    \draw (0,-0.5) node {$Z$};

    % Suspension
    \draw[-,very thick] (2.5,.5) -- (3,0.25) -- (2.5,0) -- (3,-.25) -- (2.5,-.5) -- (3,-.75) -- (2.5,-1) -- (3,-1.25) -- (2.5,-1.5) -- (3,-1.75);
    \draw (2,-0.5) node {$K_s$};

    \draw[-,very thick] (5,.5) -- (5,-.3);
    \draw[draw=black,fill=black,very thick] (4.7,-.3) rectangle (5.3,-.5);
    \draw[-,very thick] (4.5,-.3) -- (4.5,-.7) -- (5.5,-.7) -- (5.5,-.3);
    \draw[-,very thick] (5,-.7) -- (5,-1.75);
    \draw (6,-0.5) node {$C_s$};
    \draw (10,-0.5) node {Suspension};

    % Unsprung mass
    \shade[top color=gray, bottom color=white, shading angle={135}]
        [draw=black,fill=gray!20,rounded corners=1.2ex,very thick] (2,-1.75) rectangle (6,-2.75);
    \draw (10,-2.25) node {Unsprung mass};      
    \draw (4,-2.25) node {$m$};

    \draw[->,very thick] (2,-2.25) -- (0,-2.25) -- (0,-3.75);
    \draw (0,-4.25) node {$Z_u$};

    % Tire
    \draw[-,very thick] (3.75,-2.75) -- (4.25,-3) -- (3.75,-3.25) -- (4.25,-3.5) -- (3.75,-3.75) -- (4.25,-4) -- (3.75,-4.25) -- (4.25,-4.5) -- (3.75,-4.75) -- (4.25,-5);
    \draw (3.25,-4) node {$K_t$};
    \draw (10,-4) node {Tire};

    % Road
    \draw[-,thick] (0.5,-5) -- (0.0,-5.5);
    \draw[-,thick] (1.0,-5) -- (0.5,-5.5);
    \draw[-,thick] (1.5,-5) -- (1.0,-5.5);
    \draw[-,thick] (2.0,-5) -- (1.5,-5.5);
    \draw[-,thick] (2.5,-5) -- (2.0,-5.5);
    \draw[-,thick] (3.0,-5) -- (2.5,-5.5);
    \draw[-,thick] (3.5,-5) -- (3.0,-5.5);
    \draw[-,thick] (4.0,-5) -- (3.5,-5.5);
    \draw[-,thick] (4.5,-5) -- (4.0,-5.5);
    \draw[-,thick] (5.0,-5) -- (4.5,-5.5);
    \draw[-,thick] (5.5,-5) -- (5.0,-5.5);
    \draw[-,thick] (6.0,-5) -- (5.5,-5.5);
    \draw[-,thick] (6.5,-5) -- (6.0,-5.5);
    \draw[-,thick] (7.0,-5) -- (6.5,-5.5);
    \draw[-,thick] (7.5,-5) -- (7.0,-5.5);
    \draw[-,thick] (8.0,-5) -- (7.5,-5.5);
    \draw[-,thick] (8.5,-5) -- (8.0,-5.5);
    \draw[->,very thick] (8.5,-5) -- (0,-5) -- (0,-6.5);
    \draw (0,-7) node {$Z_r$};
\end{tikzpicture}

\end{document}

and the result is this one:

Quarter-car model

The question is not how draw this model, but if there is a better and shorter way to draw it with a simpler code than mine.

Best Answer

This is my try using Tikz. It was quite a work, but the code should be substantially shorter and easier to understand.

Changes and implementations:

  1. Used a foreach command to draw the little diagonal lines. One line instead of all of those you had to write.
  2. In order to make the connector shape, I tweaked Jake's solution fixing the thickness and so on.
  3. Set the node properties inside a \tikzset. This way you only need to type one keyword to activate multiple options. Result: saving of space.
  4. I did the nodes first and the paths later for organization purposes. The nodes at the right were originally made with labels, but writing them using nodes was easier in terms of positioning.
  5. The zigzag lines were created using decorations, and positioning nodes at the midway position. They all use the properties inside of snake arrow, so if you edit there, all paths using this key will be modified.
  6. Positionings, calculations, arrows, decorations were all done using the Tikz libraries, check the preamble. This might come in handy for you in the future.

Output

figure 1

Code

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{arrows, calc,decorations.pathmorphing,positioning,decorations.markings}

\tikzset{
    shadedrec/.style={
        rectangle,
        draw=black,
        top color=gray, 
        bottom color=white, 
        shading angle={135},
        text width=3cm,
        inner sep=1em,
        rounded corners=1.2ex,
        very thick,
        text centered},
    snake arrow/.style={
        decorate,
        decoration={zigzag,amplitude=3mm,segment length=5mm,post length=0mm}},
    damper/.style={
        very thick,
        decoration={markings,  
        mark connection node=dmp,
        mark=at position 0.5 with 
        {
            \node (dmp) [very thick,transform shape,text width=.3cm,rotate=-90,minimum height=3pt,draw=none, fill=black,outer xsep=2pt, outer ysep=1pt] {};
            \draw [very thick] ($(dmp.north east)+(-.6pt,0)$) -- ($(dmp.south east)+(-.6pt,0)$) -- ($(dmp.south west)+(-.6pt,0)$) -- ($(dmp.north west)+(-.6pt,0)$);
            \draw [very thick,rotate=-90] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
        }
    }, decorate}
}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}

% Shapes

    \node[shadedrec, anchor=center] (S1) at (4,3) {$M$};
    \node[shadedrec, anchor=center, below=2 of S1] (S2) {$m$};

%Nodes side
    \node[anchor=center,text centered,right=2cm of S1.east] (sm) {Sprung mass};
    \node[below=of sm] (susp) {Suspension};
    \node[below=of susp] (usm) {Unsprung mass};
    \node[below=of usm] {Tire};

% Paths

%side arrows
    \draw[->,very thick] (S1.west) -- ++ (-1.5,0) -- ++ (0,-1.5) node[below] {$Z$};
    \draw[->,very thick] (S2.west) -- ++ (-1.5,0) -- ++ (0,-1.5) node[below] {$Z_u$};

%zigzag lines
    \draw[very thick, snake arrow] ($(S1.south west)!.5!(S1.south)$) -- ++ (0,-2) node[left,midway,xshift=-1em] {$K_s$};
    \draw[very thick, snake arrow] (S2.south) -- ++ (0,-2) 
        node[left,midway,xshift=-1em] {$K_t$};

%Connector shape
    \draw[damper] ($(S2.north east)!.5!(S2.north)$) -- ($(S1.south east)!.5!(S1.south)$) node[right,midway,xshift=1em] {$C_s$};


% Road
    \coordinate (A) at ($(S2.west)+(5.5,-2.45)$);
    \draw[->,very thick] (A) -- ++(-7,0) -- ++ (0,-1.5) node[below] {$Z_r$};

\begin{scope}[shift={($(S2.west)+(-1.5,-2.45)$)}]

    \foreach \x in {0.5,1,...,7} { %This one draws the little diagonal lines
    \draw (\x,0) -- ({\x-.5},-.5);
    }

\end{scope} 
\end{tikzpicture}

\end{document}
Related Question