10

Is it possible to place nodes along a hobby curve such that the orientation is tangential to the curve. I should add what I mean with tangential: The curved hobby path should represent a curvy street and then I would add an image of a car at a given position on the path such that the car points tangential to the curve. I tried to make it more clear with the following pseudo-code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}
\usepackage{graphicx}

\begin{document}
\begin{tikzpicture}
\draw
(0,0) to[out angle=0,in angle=180,curve through={(1,.9) ..node[rotation=tangential,pos=0.4]{\includegraphics[width=0.5cm]{car}} (2,0) .. (3,.5)}] (4,0);
\end{tikzpicture}
\end{document}

Take for example this car picture:

14

Loath as I am to admit it, but there's nothing particular to hobby here. The decorations libraries allow you to do this: they work along a curve without regard for how it was generated (so it can be generated by Hobby's algorithm) and "do stuff" as they go. When they do whatever it is that they do then they are in a coordinate frame where x points tangential to the curve and y is normal. Thus:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/81812/86}
\usepackage{tikz}
\usetikzlibrary{hobby,decorations.markings}
\usepackage{graphicx}

\begin{document}
\begin{tikzpicture}
\draw[
  postaction={
    decorate,
    decoration={
      markings,
      mark=at position 0.4 with
      {
        \draw[->,ultra thick,green] (-1,0) -- (1,0);
      }
    }
  }
]
(0,0) to[out angle=0,in angle=180,curve through={(1,.9) .. (2,0) .. (3,.5)}] (4,0);
\end{tikzpicture}
\end{document}

(Sorry, not good at drawing cars.)

tangential line to curve

If the marking contains a node then you will want to use the transform shape key if you want to ensure that the node rotates to fit the tangential coordinate system (recall that nodes tend not to obey all the surrounding transformations unless explicitly told to do so).

With the graphic from the question saved as car.png:

\documentclass{standalone}
%\url{http://tex.stackexchange.com/q/81812/86}
\usepackage{tikz}
\usetikzlibrary{hobby,decorations.markings}
\usepackage{graphicx}

\begin{document}
\begin{tikzpicture}
\draw[
  postaction={
    decorate,
    decoration={
      markings,
      mark=between positions 0 and 1 step 0.2 with
      {
        \node[transform shape] {\includegraphics[width=.5cm]{car}};
      }
    }
  }
]
(0,0) to[out angle=0,in angle=180,curve through={(1,.9) .. (2,0) .. (3,.5)}] (4,0);
\end{tikzpicture}
\end{document}

cars driving along a curve

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.