3

I want to use Bezier curves to draw a track in TikZ, e.g., a racetrack.

I have the centerline of the track specified with the help of Bezier curves, like this:

\documentclass[11pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
  \draw[dashed,blue] (0,0) .. controls (1,1) and (2,-1) .. (3,0);
\end{tikzpicture}
\end{document}

I now want to draw the boundary of the track which is always a distance d from the centerline.

What is the best way to achieve this?

3
  • Welcome! You have some code which you now want to adapt. You don't know how to do it. However, you think that we, who do not have any idea what your code contains, will be able to tell you. Do you see the problem? Please edit your question to include code for a minimal document which shows the problem and which we can copy-paste-compile to produce the centreline. However, your best bet is to add double, double distance=<width between lines>, line width=<width of each line> etc. to the existing path.
    – cfr
    Jan 18, 2017 at 2:44
  • Sorry I was a bit lazy. Thanks for your great answer!
    – miga89
    Jan 18, 2017 at 2:58
  • Thanks for editing. Could you post your answer as an answer? It doesn't make sense to have it in the question.
    – cfr
    Jan 18, 2017 at 3:03

1 Answer 1

4

As @cfr pointed out, this is easily achievable with the double distance key. Hence, the following code achieves what I want:

\documentclass[11pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}

   \draw[solid,red,double distance=10pt] (0,0) .. controls (1,1) and (2,-1) .. (3,0);
   \draw[dashed,blue] (0,0) .. controls (1,1) and (2,-1) .. (3,0);

\end{tikzpicture}

\end{document}

enter image description here

1
  • @cfr: Any idea how to get rid of these small gray lines at the start and end of the border?
    – miga89
    Jan 24, 2017 at 6:43

You must log in to answer this question.

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