6

I found this nice car from here.

    \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}

Is there any way to make this car smaller? I don't get what these numbers are: (1.5,.5) -- ++(0,1) -- ++(1,0.3) -- ++(3,0) -- ++(1,0) -- ++(0,-1.3) -- (1.5,.5) -- cycle and (2.5,1.8) -- ++(1,0.7) -- ++(1.6,0) -- ++(0.6,-0.7) -- (2.5,1.8);

enter image description here

  • The numbers are positions over a 2D plane, units by default are centimetres. And ++(x,y) represents a coordinate positioned (x,y) from previous one. – Ignasi Oct 4 '16 at 9:21
9

The easiest way to scale one part of a picture is to put inside a scope environment.

\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}

\begin{tikzpicture}
  \begin{scope}[scale=0.5]
    \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);
  \end{scope}

  \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}

\begin{tikzpicture}
  \begin{scope}[xscale=0.5,yscale=1.2,xshift=5cm]
    \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);
  \end{scope}

  \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

  • Wow, that's exactly what I was looking for. Thanks – m0_as Oct 4 '16 at 7:53
  • Is it possible to shift picture using this scope? I mean for example I want to have two cars beside each other. – m0_as Oct 4 '16 at 7:58
  • 1
    Yes, put two scopes, one for each car, in the same picture and use xshift and yshift. – StefanH Oct 4 '16 at 8:38

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.