Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

share|improve this question
    
Where do you have this nice picture of a car from? –  moose Dec 19 '13 at 16:42
    
I asked google for "car top view". Then you find for example this: 4vector.com/free-vector/red-racing-car-top-view-99252 or this clker.com/clipart-red-car-top-view-11.html –  student Dec 19 '13 at 17:45
    
What a nice website. Thanks for sharing! –  moose Dec 19 '13 at 18:53

1 Answer 1

up vote 12 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.