I would like to be able to draw tikz pictures that generalize the following one:

\draw (0,0) to (1,0);
\foreach \n in {.1,.2,...,.9} \draw (\n,0) to (\n,.1);

The result of the above code is a horizontal line with short "hairs" growing off one side, perpendicular to the curve. I want to achieve this effect but for curves that bend in customized ways, for example by specifying a number of points they pass through along with in and out angles at each one. In that case, I can't just repeat the above strategy, since the exact endpoints of the hairs are determined in a complicated way by the points and in/out angles used to define the curve. Any ideas?


Shamelessly using this great tangent line answer to sort out your problem. Try the following code:



    tangent/.style={decoration={markings,mark=at position #1 with {
      \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
      \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
      \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
    use tangent/.style={
        shift=(tangent point-#1),
        x=(tangent unit vector-#1),
        y=(tangent orthogonal unit vector-#1)
    use tangent/.default=1
% Define your path here
\def\PTH{(0,0) to [out=20,in=120] (5,2) to [out=-60, in=110] (9,1)}
% Choose the number of "hairs" here
\draw \PTH;
\foreach \x in {1,...,\tans}{
  \path[tangent=\x/\tans] \PTH;
  \draw [blue, thick, use tangent=1] (0,0) -- (0,.5);

This should give you the following picture:

enter image description here

Note that you can change the length of the "hairs," which are now set to 0.5 in the foreach loop. Also, if you change the endpoint of the "hairs" to be (.5,0) instead, then you will get short hairs that are tangent to the path.

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.