6

Is there a way to define a 90-degrees-angle pattern for (straight) lines in TikZ? a line with angles pattern

The pattern should follow the line direction.

9

If you don't mind white painted arrows then it is kind of easy but might need tweaking to get the spacing right.

\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{decorations.markings,arrows.meta}
\begin{document}
\begin{tikzpicture}[arrow marks/.style={
  decoration={
    markings,pre length=2\pgflinewidth,post length=.5\pgflinewidth,
    mark={
      between positions 0 and 1 step 0.2 with {
      \arrow[white,line width=1.1\pgflinewidth]{Fast Triangle}
        }
      }
    }
  }
]
\draw[line cap=round,line width=5mm,postaction=decorate,arrow marks] (0,0) -- (5,0);
\end{tikzpicture}
\end{document}

enter image description here

Depending on your use case you can add more and more options where to start where to end what to do if there is a corner on the path etc. If you don't want it to be painted to white then you have to create the initial and the final parts of the path manually and place black parts instead.

  • Works great! But the distance between the ends of the line and the first (or last) angle is a bit too big. Is there a way to change it? – GeMir Jul 9 '15 at 12:15
  • 1
    @GeMir I was afraid that you would ask that :) We(I) need to take care of the length of the arrow and the decoration start/end distances. I'll do that in a finite time. – percusse Jul 9 '15 at 15:25
5

Here's a simple Metapost approach for an arbitrary path.

curved path decorated with chevrons

You could make the decoration loop into a function if you wanted to use it often.

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

z1 = origin;
z2 = (144,34);

path p; p = z1 {right} .. z2;
draw p withpen pencircle scaled 2;

% make the corners and ends squared
interim linecap := squared;
interim linejoin := mitered;
% n = number of chevrons, s=number to skip at start and end
% w = chevron width
n = 50; s=2; w=1;
for i=s upto n-s:
  undraw (left--origin--up) scaled 2 
                            rotated 45 
                            rotated angle direction i/n of p
                            shifted point i/n of p
                            withpen pencircle scaled w;
endfor

endfig;
end.

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.