9

I have a problem. In order to use a special picture in my seminar paper i need to draw the following picture:

enter image description here

The car and the arrows can be neglected but the curvy road exceeds my abilities. Tried to draw if using circles drawn on top of each other, but couldn't really make it work.

Thanks for any help.

Cheers

EDIT: Thank you guys for all these possibilites! You exceeded my expectations:)

1

4 Answers 4

17

Just for fun, since this is a repeating theme: draw a curve parallel to an existing curve. Here this is done by a decoration named street mark.

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{decorations,decorations.markings} 
\pgfkeys{/tikz/.cd,
    street mark distance/.store in=\StreetMarkDistance,
    street mark distance=10pt,
    street mark step/.store in=\StreetMarkStep,
    street mark step=1pt,
}

\pgfdeclaredecoration{street mark}{initial}
{% 
\state{initial}[width=\StreetMarkStep,next state=cont] {
    \pgfmoveto{\pgfpoint{\StreetMarkStep}{\StreetMarkDistance}}
    \pgfpathlineto{\pgfpoint{0.3\pgflinewidth}{\StreetMarkDistance}}
    \pgfcoordinate{lastup}{\pgfpoint{1pt}{\StreetMarkDistance}}
    \xdef\marmotarrowstart{0}
  }
  \state{cont}[width=\StreetMarkStep]{
     \pgfmoveto{\pgfpointanchor{lastup}{center}}
     \pgfpathlineto{\pgfpoint{\StreetMarkStep}{\StreetMarkDistance}}
     \pgfcoordinate{lastup}{\pgfpoint{\StreetMarkStep}{\StreetMarkDistance}}
  }
  \state{final}[width=\StreetMarkStep]
  { % perhaps unnecessary but doesn't hurt either
    \pgfmoveto{\pgfpointdecoratedpathlast}
  }
}

\newcommand{\testpath}{(0,0) to[out=90,in=-30] (-3,4)}
\begin{document}
  \begin{tikzpicture}[scale=1]
    \clip (-2,0) rectangle (1,3.5);
    \path[fill=green!66!black] (-2,0) rectangle (1,3.5);
    \draw[line width=30,gray] \testpath;
    \draw[draw=white,dashed,double=gray,double distance=10] \testpath;
    \draw[line width=10,gray] \testpath;
    \draw[yellow,decorate,decoration={street mark},street mark distance=13] \testpath;
    \draw[white,decorate,decoration={street mark},street mark distance=-13] \testpath;
    \draw[decorate,decoration={markings,
     mark =at position 0.4 with {\draw[white,-latex,line width=1pt](0,0)
     coordinate(top) -- (1,0);}
    }] \testpath;
    \node[fill=red,minimum width=5pt,minimum height=12pt,anchor=north,rotate=10] (car) at
    (top){};
    \draw[white,-latex,line width=1pt] (top) -- ++(100:1); 
    \draw[white,line width=1pt] (top) -- ++(100:0.3) arc(100:124:0.3); 
  \end{tikzpicture}
\end{document}

enter image description here

The disadvantage is that the code is slightly more complex, the advantage is that you can take arbitrary curves for your streets.

ADDENDUM: Added a tangent, this could be also used in Sigur's nice answer. And just for fun an animation using these tricks.

\documentclass{article}

\usepackage{animate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[active,tightpage]{preview}
\makeatletter
\def\@anim@@newframe{\@ifstar\@anim@newframe\@anim@newframe}
\def\@anim@newframe{\end{preview}\begin{preview}}
\renewenvironment{animateinline}[2][]{%
  \let\newframe\@anim@@newframe%
  \let\multiframe\@anim@multiframe%
  \begin{preview}}{%
  \end{preview}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz}
\usetikzlibrary{decorations,decorations.markings} 
\pgfkeys{/tikz/.cd,
    street mark distance/.store in=\StreetMarkDistance,
    street mark distance=10pt,
    street mark step/.store in=\StreetMarkStep,
    street mark step=1pt,
}

\pgfdeclaredecoration{street mark}{initial}
{% 
\state{initial}[width=\StreetMarkStep,next state=cont] {
    \pgfmoveto{\pgfpoint{\StreetMarkStep}{\StreetMarkDistance}}
    \pgfpathlineto{\pgfpoint{0.3\pgflinewidth}{\StreetMarkDistance}}
    \pgfcoordinate{lastup}{\pgfpoint{1pt}{\StreetMarkDistance}}
    \xdef\marmotarrowstart{0}
  }
  \state{cont}[width=\StreetMarkStep]{
     \pgfmoveto{\pgfpointanchor{lastup}{center}}
     \pgfpathlineto{\pgfpoint{\StreetMarkStep}{\StreetMarkDistance}}
     \pgfcoordinate{lastup}{\pgfpoint{\StreetMarkStep}{\StreetMarkDistance}}
  }
  \state{final}[width=\StreetMarkStep]
  { % perhaps unnecessary but doesn't hurt either
    \pgfmoveto{\pgfpointdecoratedpathlast}
  }
}

\newcommand{\testpath}{(0,0) to[out=0,in=-70] (3,3.5) to[out=110,in=0] (0,5)}
\begin{document}
\begin{animateinline}[autoplay,loop]{2}
  \multiframe{51}{i=0+1}{\pgfmathsetmacro{\mypos}{0.2+\i/100}
  \pgfmathsetmacro{\mynextpos}{\mypos+0.115}
  \begin{tikzpicture}
    \path[fill=green!66!black] (0,-0.5) rectangle (4,5.5);
    \draw[line width=30,gray] \testpath;
    \draw[draw=white,dashed,double=gray,double distance=10] \testpath;
    \draw[line width=10,gray] \testpath;
    \draw[yellow,decorate,decoration={street mark},street mark distance=13] \testpath;
    \draw[white,decorate,decoration={street mark},street mark distance=-13] \testpath;
    \draw[decorate,decoration={markings,
     mark =at position \mynextpos with {\coordinate (top);},
     mark =at position \mypos with {\coordinate (car) at    (0,0){};
    \fill[red] (6pt,3pt) -- (-6pt,3pt) -- (-6pt,-3pt) -- (6pt,-3pt) -- cycle;
     \draw[white,-latex,line width=1pt](car) -- ++ (1,0);
     \draw[white,-latex,line width=1pt](car) -- (top);}
    }] \testpath;
    ;
  \end{tikzpicture}}
\end{animateinline}  
\end{document}

enter image description here

2
  • 1
    Nice animation and code!
    – J Leon V.
    May 21, 2018 at 0:03
  • your Sir are very good at these things! Thank you very much!:) May 21, 2018 at 9:36
13

Here is a starting point. You can control the color, the line thickness and the clipping region.

enter image description here

\documentclass[margin=1pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=1] % scale the whole image
\clip (1,0) rectangle (2.7,2.3);
\coordinate (O) at (0,0);
\path[fill=green!70!black] (O) circle (3cm);
\path[fill=black!50] (O) circle (2.7cm);
\path[fill=green!70!black] (O) circle (2cm);
\draw[yellow,thin](O) circle (2.05cm);
\draw[white,thin] (O) circle (2.65cm);
\draw[loosely dashed,white,thin] (O) circle (2.25cm); % loosely dashed
\draw[loosely dashed,white,thin] (O) circle (2.45cm);
\end{tikzpicture}
\end{document}
0
12

A short code with pstricks:

\documentclass[border = 5pt, svgnames]{standalone}
\usepackage{pstricks, pst-arrow}
\usepackage{auto-pst-pdf}% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeXLive, MacTeX)
\newcommand{\pscar}{\psframe*[linecolor=Tomato, framearc=0.1](-0.15,0)(0.15,0.6)\psline[linecolor=white, showpoints, dotsize=3pt]{<->}(0,1)(0,0.3)(-0.38,1)%
\psarc[linewidth=1pt](0,0.3){0.15}{90}{120}}

     \begin{document}

\psset{unit=4cm, linewidth=2pt, linejoin=1}
     \begin{pspicture}(1.2, 0.1)(3.3, 3)
\begin{psclip}{\psframe[fillstyle = solid, fillcolor =Green](1.2, 0.1)(3.3, 3)}
\psRing*[linecolor=darkgray](0,0)[0,90]{2}{3.6}
\psarc[linecolor =yellow](0,0){2.05}{0}{90}
\psset{linecolor=white}
\psarc(0,0){3.5}{0}{90}
\rput{18}(2.67; 28){\pscar}
\rput(2.5; 45){\color{white}\bfseries angle}
\psset{ linestyle=dashed}
\psarc[dash=75pt 50pt](0,0){2.5}{0}{90}
\psarc[dash=80pt 60pt](0,0){3.0}{0}{90}
\end{psclip}
     \end{pspicture}

     \end{document} 

enter image description here

0
11

Another option by defining line styles with preactions and postasctions, the problem of this is that you can not color the marching lines of the track of different colors, for the car, use object definition by scope, through which you can rotate, This code allows to draw any type of tray and fill it with as many cars as in my city xD.

RESULT: enter image description here MWE:

\documentclass[margin=1pt]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{arrows,positioning,backgrounds}
\definecolor{grass}{HTML}{296402}
\definecolor{way}{HTML}{373737}

\begin{document}

\begin{tikzpicture}[
    %STYLES
    bg/.style={
        rectangle,
        fill=grass,
        },
    runway node/.style={% Runway 
        rounded corners,
        way,
        line width=54pt,
        preaction={
            draw,
            way,
            line width=60pt,
            },
        preaction={
            draw,
            yellow,
            line width=55pt, % Yellow border lines.
            },
        postaction={
            draw,
            white,
            line width=19pt,
            dash pattern=on 35pt off 15pt, % Here control the road division lines
            },
        postaction={
            draw,
            way,
            line width=18pt,
            },
        },
    ]

 \def\car(#1)#2{%
  \begin{scope}[shift={(#1)}, rotate={(#2)}]
    \draw[fill=red, red] (0,0) rectangle (0.4,0.8);
    \draw[->,white,>=latex,semithick] (0.2,0.4) coordinate (center) -- ++ (0,1);
    \draw[->,white,>=latex,semithick] (center) -- ++ (120:1);
    \draw[white,semithick] (center) -- ++ (90:.3) arc (90:120:.3);
    \draw[white] (center)++(105:.6) node {\small $\alpha$};
  \end{scope}
}

% Start drawing the thing ...

% Croping the draw
\clip (0,-2.5) rectangle (3,2);
%background
\node [bg, minimum height =8cm, minimum width=6cm] at (0.5,0) {} ;
%Runways
\draw[runway node] (2,-2.5) .. controls +(90:1.5cm) and +(-20:2cm) .. (-1,1.5);
%Car
\car(1.1,-0.5){25};
\end{tikzpicture}
\end{document}

OPTIONAL RESULT:

enter image description here

OPTIONAL MWE:

% Start drawing the thing... 

%background
\node [bg, minimum height =20cm, minimum width=15cm] at (0.5,0) {} ;
%Runways
\draw[runway node] (5.5,-5) .. controls +(60:7cm) and +(-120:3cm) .. (-2.5,5) -- (0,8.5) -|(5.5,6);
\draw[runway node] (5.5,-5) .. controls +(-120:6cm) and +(-140:5cm) .. (-2.5,-1) -- (2.5,3.5) -|(5.5,6);
%Cars
\car(5.5,-3.6){0};
\car(-0.7,-6.3){-120};
\car(-2.1,3.4){25};
\car(-.6,-0){-50};
\car(5.6,6){0};
\car(5,-0.5){25};
\car(0,8.5){145};
1
  • @TikzerWoods, I did not know that magic, I do not know if this one could define entries because under def, I can control the angle, and the color of the car, to dimension the vectors \car (position){rotantion}{color}{angle}{vector_module}
    – J Leon V.
    May 21, 2018 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .