5

I want in tikz environment pattern an area with arrows. and how I can control the density of arrow (for example: number of arrow on area)?

enter image description here

7

One option using the intersections library:

enter image description here

The code:

\documentclass[border=5pt]{standalone} 
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{intersections,arrows.meta}

\NewDocumentCommand\DrawArrows{O{0.5}mmO{-latex}mm}{
\def\Step{#1}
\pgfmathsetmacro{\Second}{#5+\Step}
\foreach \Value [count=\xi] in {#5,\Second,...,#6}
  {
  \path[overlay,name path=line\xi] 
    (\Value,100) -- (\Value,-100);
  \path[name intersections={of=#2 and line\xi,by={1\xi}}];
  \path[name intersections={of=#3 and line\xi,by={2\xi}}];
  \ifdim#5pt<\Value pt\relax
    \ifdim\Value pt<#6pt\relax
    \draw[#4]
      (1\xi) -- (2\xi); 
  \fi\fi
  }
}

\begin{document}

\begin{tikzpicture}
\draw[name path=curve1,ultra thick]
  (0,0) .. controls ++(1,5) and ++(0,3) .. (7,2);
\draw[name path=curve2,ultra thick]
  (0,0) -- (7,2);
\DrawArrows{curve1}{curve2}{0}{7}  
\begin{scope}[xshift=8cm]
\draw[name path=curve1,ultra thick]
  (0,0) .. controls ++(1,5) and ++(0,3) .. (7,2);
\draw[name path=curve2,ultra thick]
  (0,0) -- (7,2);
\DrawArrows[0.25]{curve1}{curve2}[Stealth-Stealth,cyan]{0}{7}  
\end{scope}
\begin{scope}[yshift=-5cm]
\draw[name path=curve1,ultra thick]
  (0,0) .. controls ++(1,5) and ++(0,3) .. (7,2);
\draw[name path=curve2,ultra thick]
  (0,0) -- (7,2);
\DrawArrows[1]{curve2}{curve1}[ultra thick,orange,-{Triangle[length=10pt]}]{0}{7}  
\end{scope}
\begin{scope}[xshift=8cm,yshift=-5cm]
\draw[name path=curve1,ultra thick]
  (0,0) .. controls ++(1,5) and ++(0,3) .. (7,2);
\draw[name path=curve2,ultra thick]
  (0,0) -- (7,2);
\DrawArrows[0.125]{curve2}{curve1}{2}{5}  
\end{scope}
\end{tikzpicture}

\end{document}

Explanation

The main command is \DrawArrows. You draw the two paths and name them <name1>, <name2>, and then you use

\DrawArrows{<name1>}{<name2>}{<start x-coordinate>}{<end x-coordinate>}

An optional first argument allows to control the step used for (the density of) the arrows and a second optional argument gives control over the arrow attributes (tip, color, line width, etc.).

| improve this answer | |
8

If you can define the top and bottom paths in terms of functions, it is straightforward:

\documentclass[tikz,border=5]{standalone}
\tikzset{declare function={
  f(\x)=sin(\x/1.5)^2*2;
  g(\x)=-sin(\x*2)*sin(\x);
}}
\begin{document}
\begin{tikzpicture}[x=1pt, very thick, >=stealth]
\foreach \c [count=\k, 
  evaluate={\s=int(30); \e=int(150); \t=\s+\k*5;}] in {red, green, blue}{
\tikzset{shift=(270:\k*3)}
\draw [thick, samples=100, smooth] plot [domain=0:180] (\x, {f(\x)}) -- 
  plot [domain=180:0] (\x, {g(\x)}) -- cycle;
\foreach \i in {\s, \t,..., \e}
   \draw [draw=\c, <->] (\i, {f(\i)}) -- (\i, {g(\i)});
}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

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.