# TikZ - Vehicle Suspension

I am new to TikZ (still learning), so I am not able to create complex tikzpictures (only simple shapes), but I was wondering if someone can give me tips/links/examples about how to create an vehicle suspension in simple 2D.

Something like (but in 2D):

-
I think you need SolidWorks not TikZ. – percusse Jan 14 '13 at 12:20
If you want to draw things close to photorealistic, you should go for some construction program or (if functional stuff and exact sizes is not necessary) a 3D rendering program. TikZ is very well suited for schematic drawings but not for stuff that should look like it was a photograph. – Benedikt Bauer Jan 14 '13 at 12:22
Maybe you want to draw a simple 2D representation of it, no? – marczellm Jan 14 '13 at 12:41
@marczellm yes, I want to draw a simple 2d picture not a realistic one. – user24386 Jan 14 '13 at 12:43
This kind of suspension is mechanically a spring-dashpot system. A schematic drawing of such a system can be found here: Spring-Dashpot – Dohn Joe Jan 14 '13 at 17:33

Here's a first attempt (which clearly admits improvements); basically I used superimposed cylinders and the coilup, coildown decorations provided in this answer by Hans-Peter E. Kristiansen:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,patterns,shapes.geometric}

\usepgfmodule{decorations}

\makeatletter
% coilup, coildown decorations
% code by Hans-Peter E. Kristiansen
% in http://tex.stackexchange.com/a/43605/3954
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength,

\pgfdeclaredecoration{coilup}{coil}
{
\state{coil}[switch if less than=%
1.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude to last,
width=+\pgfdecorationsegmentlength]
{
\pgfpathcurveto
{\pgfpoint@oncoil{0    }{ 0.555}{1}}
{\pgfpoint@oncoil{0.445}{ 1    }{2}}
{\pgfpoint@oncoil{1    }{ 1    }{3}}
\pgfpathmoveto{\pgfpoint@oncoil{1    }{-1    }{9}}
\pgfpathcurveto
{\pgfpoint@oncoil{0.445}{-1    }{10}}
{\pgfpoint@oncoil{0    }{-0.555}{11}}
{\pgfpoint@oncoil{0    }{ 0    }{12}}
}
\state{last}[width=.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude,next state=final]
{
\pgfpathcurveto
{\pgfpoint@oncoil{0    }{ 0.555}{1}}
{\pgfpoint@oncoil{0.445}{ 1    }{2}}
{\pgfpoint@oncoil{1    }{ 1    }{3}}
\pgfpathmoveto{\pgfpoint@oncoil{2    }{ 0    }{6}}
}
\state{final}
{
\pgfpathmoveto{\pgfpointdecoratedpathlast}
}
}

% coildown decoration
%
% Parameters: \pgfdecorationsegmentamplitude, \pgfdecorationsegmentlength,

\pgfdeclaredecoration{coildown}{coil}
{
\state{coil}[switch if less than=%
1.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude to last,
width=+\pgfdecorationsegmentlength]
{
\pgfpathmoveto{\pgfpoint@oncoil{1    }{1    }{3}}
\pgfpathcurveto
{\pgfpoint@oncoil{1.555}{ 1    }{4}}
{\pgfpoint@oncoil{2    }{ 0.555}{5}}
{\pgfpoint@oncoil{2    }{ 0    }{6}}
\pgfpathcurveto
{\pgfpoint@oncoil{2    }{-0.555}{7}}
{\pgfpoint@oncoil{1.555}{-1    }{8}}
{\pgfpoint@oncoil{1    }{-1    }{9}}
}
\state{last}[width=.5\pgfdecorationsegmentlength+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude+%
\pgfdecorationsegmentaspect\pgfdecorationsegmentamplitude,next state=final]
{
\pgfpathmoveto{\pgfpoint@oncoil{1    }{ 1    }{3}}
\pgfpathcurveto
{\pgfpoint@oncoil{1.555}{ 1    }{4}}
{\pgfpoint@oncoil{2    }{ 0.555}{5}}
{\pgfpoint@oncoil{2    }{ 0    }{6}}
}
\state{final}
{
\pgfpathlineto{\pgfpointdecoratedpathlast}
}
}

\def\pgfpoint@oncoil#1#2#3{%
\pgf@x=#1\pgfdecorationsegmentamplitude%
\pgf@x=\pgfdecorationsegmentaspect\pgf@x%
\pgf@y=#2\pgfdecorationsegmentamplitude%
\pgf@xa=0.083333333333\pgfdecorationsegmentlength%
}
\makeatother

\definecolor{myorange}{RGB}{238,97,26}

\begin{document}

\begin{tikzpicture}
\draw[fill=gray!30]
(-0.5,-0.8) .. controls (-1.4,-2.3) and (1.4,-2.3) .. (0.5,-0.8);
\draw[fill=white]
(0,-1.3) circle (0.3cm);
\node[cylinder,
fill=myorange,
rotate=90,
draw,
minimum height=0.7cm,
minimum width=1.5cm,
anchor=east]
at (0,-0.15)  {};
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=0.5cm,
minimum width=2cm,
anchor=east]
at (0,0.1)  {};
\draw[decoration={
aspect=0.3,
segment length=3mm,
amplitude=10mm,coilup,
segment length=10pt},
decorate,
double=myorange,
double distance=2pt]
(0,5) -- (0,0);
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=2cm,
minimum width=0.4cm,
anchor=east,aspect=0.3]
at (0,2)  {};
\node[cylinder,
fill,
rotate=90,
draw,
minimum height=3.1cm,
minimum width=1.4cm,
anchor=east]
at (0,5)  {};
\draw[decoration={
aspect=0.3,
segment length=3mm,
amplitude=10mm,coildown,
segment length=10pt},
decorate,
double=myorange,
double distance=2pt]
(0,5) -- (0,0);
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=0.5cm,
minimum width=2cm,
anchor=east]
at (0,5.2)  {};
\node[cylinder,
fill,
rotate=90,
draw,
minimum height=1cm,
minimum width=1.4cm,
anchor=east]
at (0,6)  {};
\node[cylinder,
fill=gray!30,
rotate=90,
draw,
minimum height=0.5cm,
minimum width=1.6cm,
anchor=east]
at (0,6)  {};
\draw[fill=gray!30]
(-0.5,5.9) .. controls (-1.4,7.5) and (1.4,7.5) .. (0.5,5.9);
\draw[fill=white]
(0,6.5) circle (0.3cm);
\end{tikzpicture}

\end{document}


-
This is great, exactly what I was looking for, thank you! – user24386 Jan 16 '13 at 9:20

The clue in schematic drawing things (not only in TikZ) is to break things down to very basic forms. To give an example for your suspension: you don't have to care about "How the hell will I get the spring windings look like they lie partially behind the damping rod and partially in front?" but reduce stuff to make it simple but easily recognizable. For example the typical zig-zag line that represents springs in physical or technical drawings should be close enough to see what you mean.

A second very useful feature of TikZ is generalization. You can easily define own styles or macros for certain things. If you want for example the thread to be black and with a zig-zag edge in all of your drawings, you can define a global style to do so and then can apply this style to all threads you want to draw.

For a nice compilation of things that are possible and the code behind them, take a look at texample.net. You will be surprised how less code can be necessary to draw very elaborate looking figures. In many cases you will not understand the whole code immediately, but don't give up on this but take the code and play around with it to see how things change on your edits. This will make you learn new features step by step and enable you to address things more and more in detail and also more straightforward.

Just don't give up too early, TikZ can have a rather steep learning curve. Especially if you have a certain drawing in mind that you want to achieve, you will think you can never reach it but you have to go step by step and address one thing after the other. And, most important: keep the TikZ manual at hand, in best case as PDF on your computer that is opened all the time. It contains some nice tutorials to start with and is very comprehensive, explaining nearly every piece of code.

Above that there are some packages based on TikZ which define some extra functionalities, such as drawing electric circuits, plot data etc. I don't know if there is already something for drawing mechanical stuff but I wouldn't be surprised.

-