How to draw a curved street by TikZ

You can use a preaction to draw a very thick black line before a white line, or even combine it with a postaction to draw black, white, black from the outside in. It's not perfect, as you have to think about the order in that you're drawing, but you can remedy that by using layers via \pgfdeclarelayer{<name>} and \pgfsetlayers{<layer list>}.

Code

\documentclass[tikz, border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
    \draw[preaction={draw, line width=1cm, black}, white, line width=1mm] (0,-4) -- (0,4);
    \draw[preaction={draw, line width=1cm, black}, white, line width=1mm] (-0.4,0) to[out=180, in=90, looseness=2] (-4,-4);
\end{tikzpicture}

\begin{tikzpicture}
\begin{scope}
[   road/.style={
    preaction={draw, line width=10mm, black}, 
    white, line width=8mm, 
    postaction={draw, line width=1mm, black, loosely dashed}}   
]
    \draw[road] (0,-4) -- (0,4);
    \draw[road] (-0.4,0) to[out=180, in=90, looseness=2] (-4,-4);
\end{scope}
\end{tikzpicture}

\end{document}

Output

enter image description here


You can also use double line:

\documentclass[tikz, border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
    \draw[double =white,double distance=1cm,line width=1mm] (0,-4) -- (0,4) -- (0,0)
                                                            to[out=180, in=90, looseness=2] (-4,-4);
\end{tikzpicture}

\begin{tikzpicture}
    \draw[double =black,double distance=1.1cm] (0,-4) -- (0,4) -- (0,0)
                                                            to[out=180, in=90, looseness=2] (-4,-4);
    \draw[white,line width=1mm, loosely dashed] (0,-4) -- (0,4) ;
    \draw[white,line width=1mm, loosely dashed] (-0.4,0) to[out=180, in=90, looseness=2] (-4,-4);
\end{tikzpicture}

\end{document}

enter image description here


So this is my final result:

\documentclass[class=minimal,border=0pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta}

\begin{document}
\begin{tikzpicture}

\draw[double=white,double distance=2cm,ultra thick] (0,-4) -- (0,4) -- (0,0) to[out=180, in=90, looseness=2] (-4,-4);
\draw[thick,dashed] (-1,0) to[out=180, in=90, looseness=2] (-4,-4);
\draw[thick,dashed] (0,-4) -- (0,4);
\node (CAR1) at (-3.5,-3.2) [rectangle,draw,thick,minimum width=0.5cm,minimum height=0.9cm] {};
\node (CAR2) at (-1.7,-0.5) [rectangle,draw,thick,minimum width=0.5cm,minimum height=0.9cm,rotate=90] {};

\node (T1) at (-3.5,-3.1) [regular polygon,regular polygon sides=3,fill=black,minimum height=0.4cm] {};
\node (T2) at (-1.5,-0.5) [regular polygon,regular polygon sides=3,fill=black,minimum height=0.4cm,rotate=30] {};

\draw[thick,blue] (-1,-0.5) to[out=180, in=90, looseness=2] (-3.5,-2.8);
\draw[thick,red] (-3.5,-2.8) -- (-2.1,-0.5);

\draw[thick,dotted] (-3.5,-2.8) -| (-2.1,-0.5);

\end{tikzpicture}
\end{document}

But how can I remove these lines(?):

enter image description here

Tags:

Tikz Pgf