Draw a car profile with TikZ

A vintage car:

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
    \shade[top color=red, bottom color=white, shading angle={135}]
        [draw=black,fill=red!20,rounded corners=1.2ex,very thick] (1.5,.5) -- ++(0,1) -- ++(1,0.3) --  ++(3,0) -- ++(1,0) -- ++(0,-1.3) -- (1.5,.5) -- cycle;
    \draw[very thick, rounded corners=0.5ex,fill=black!20!blue!20!white,thick]  (2.5,1.8) -- ++(1,0.7) -- ++(1.6,0) -- ++(0.6,-0.7) -- (2.5,1.8);
    \draw[thick]  (4.2,1.8) -- (4.2,2.5);
    \draw[draw=black,fill=gray!50,thick] (2.75,.5) circle (.5);
    \draw[draw=black,fill=gray!50,thick] (5.5,.5) circle (.5);
    \draw[draw=black,fill=gray!80,semithick] (2.75,.5) circle (.4);
    \draw[draw=black,fill=gray!80,semithick] (5.5,.5) circle (.4);

    \draw[->,semithick] (0,-.5) -- (0,3);
    \draw (0,3.5) node {$r[x(t)]$};
    \draw[->,semithick] (-.5,0) -- (8,0);
    \draw (8.5,0) node {$x(t)$};
\end{tikzpicture}
\end{document}

enter image description here


Here's a trolley bus / tram in case you are open to public transportation:

trolley bus tram

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning,backgrounds}

\begin{document}
  \begin{tikzpicture}
    [
      olwyn/.style={circle, draw, thick, minimum width=5pt, inner sep=0pt, fill=gray!75},
      ]
    \path [draw, thick]
      coordinate (trolley) ++(-.2,2.75pt) node (w1) [olwyn] {}
        ++(.425,0) node (w2) [olwyn] {}
        ++(.425,0pt) node (w3) [olwyn] {};
    \path [draw, fill]
      (w1) circle (1pt)
      (w2) circle (1pt)
      (w3) circle (1pt);
    \path [draw, left color=red!75!black, right color=red!75!black!20]
      (trolley) ++(-.4,1.5pt) coordinate (t1) |- ++(1.25,.35) coordinate (t2) |- (w3.south east -| w3.east) |- (w3.west) |- (w2.south east -| w2.east) |- (w2.west) |- (w1.south east -| w1.east) |- (w1.west) -- (w1.south west -| w1.west) -| cycle
      (t1 -| t2) ++(-.05pt,4pt) coordinate (t3) |- ++(-.175,.175) coordinate (t4) |- cycle
      (t3 -| t4) ++(-.5pt,0) |- ++(-.25,.175) coordinate (t5) |- cycle
      (t3 -| t5) ++(-.5pt,0) |- ++(-.25,.175) coordinate (t6) |- cycle
      (t3 -| t6) ++(-.5pt,0) |- ++(-.25,.175) coordinate (t7) |- cycle
      (t3 -| t7) ++(-.5pt,0) |- ++(-.25,.175) coordinate (t8) |- cycle;
    \scoped [on background layer] \fill [left color=gray!75!blue!50, right color=gray!75!blue!10] (t3) rectangle (t8);
  \end{tikzpicture}
\end{document}

EDIT

I just turned this into a TikZ library for my own use. As libraries go, it is extremely simplistic. It does just one thing: offers a pic called tram. But I thought I might as well post it:

\ProvidesFile{tikzlibrarytrambws.code.tex}
\usetikzlibrary{backgrounds}
\colorlet{lliwytram}{red!75!black}
\colorlet{lliwffenestri}{gray!75!blue}
\colorlet{lliwolwynion}{gray!75}
\tikzset{
  lliw y tram/.code={
        \colorlet{lliwytram}{#1}
  },
  lliw ffenestri/.code={
        \colorlet{lliwffenestri}{#1}
  },
  lliw olwynion/.code={
        \colorlet{lliwolwynion}{#1}
  },
  olwyn/.style={circle, draw, line width=#1*.8pt, minimum width=#1*5pt, inner sep=0pt, fill=lliwolwynion},
  pics/tram/.style={
        code={
          \path [draw, line width=#1*.8pt]
          coordinate (tram) ++(-.2*#1,#1*2.75pt) node (w1) [olwyn=#1] {}
                  ++(#1*.425,0) node (w2) [olwyn=#1] {}
                  ++(#1*.425,0) node (w3) [olwyn=#1] {};
          \path [draw, fill, line width=#1*.4pt]
                (w1) circle (#1*1pt)
                (w2) circle (#1*1pt)
                (w3) circle (#1*1pt);
          \path [draw, left color=lliwytram, right color=lliwytram!20, line width=#1*.4pt]
                (tram) ++(-.4*#1,#1*1.5pt) coordinate (t1) |- ++(#1*1.25,#1*.35) coordinate (t2) |- (w3.south east -| w3.east) |- (w3.west) |- (w2.south east -| w2.east) |- (w2.west) |- (w1.south east -| w1.east) |- (w1.west) -- (w1.south west -| w1.west) -| cycle
                (t1 -| t2) ++(-.05*#1pt,#1*4pt) coordinate (t3) |- ++(-.175*#1,#1*.175) coordinate (t4) |- cycle
                (t3 -| t4) ++(-.5*#1pt,0) |- ++(-.25*#1,.175*#1) coordinate (t5) |- cycle
                (t3 -| t5) ++(-.5*#1pt,0) |- ++(-.25*#1,.175*#1) coordinate (t6) |- cycle
                (t3 -| t6) ++(-.5*#1pt,0) |- ++(-.25*#1,.175*#1) coordinate (t7) |- cycle
                (t3 -| t7) ++(-.5*#1pt,0) |- ++(-.25*#1,.175*#1) coordinate (t8) |- cycle;
          \scoped [on background layer] \fill [left color=lliwffenestri!50, right color=lliwffenestri!10] (t3) rectangle (t8);
        }
  }
}
\endinput

To draw a tram, you say

\pic {tram=1};

where 1 is a scaling factor. So 2 will draw a tram twice as large and .5 will draw a tram twice as small.

If you want to change the colouring, you can use

lliw y tram=<colour of tram>
lliw olwynion=<colour of wheels>
lliw ffenestri=<colour of windows>

The defaults are red!75!black, gray!75 and gray!75!blue respectively.

For example:

\documentclass[tikz,border=5pt,11pt]{standalone}
\usetikzlibrary{trambws}

\begin{document}
  \begin{tikzpicture}
    \pic  at (0,.5) {tram=.5};
    \pic [lliw y tram=blue] {tram={1}};
    \pic [lliw olwynion=green!50!gray, lliw ffenestri=green!25!white!75!gray, lliw y tram=green!75!black] at (0,-1) {tram=2};
  \end{tikzpicture}
\end{document}

various trams

Tags:

Tikz Pgf