Drawing street curve

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


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}

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

Tags:

Tikz Pgf