Processing math: 100%

Sunday, June 15, 2014

[Tikz] Draw contours with midway arrow

The code is as follows: In the preamble, paste (with the package "tikz" loaded of course!):
 \usetikzlibrary{decorations.pathreplacing,decorations.markings}  
 \tikzset{  
  % style to apply some styles to each segment of a path  
  on each segment/.style={  
   decorate,  
   decoration={  
    show path construction,  
    moveto code={},  
    lineto code={  
     \path [#1]  
     (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);  
    },  
    curveto code={  
     \path [#1] (\tikzinputsegmentfirst)  
     .. controls  
     (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)  
     ..  
     (\tikzinputsegmentlast);  
    },  
    closepath code={  
     \path [#1]  
     (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);  
    },  
   },  
  },  
  % style to add an arrow in the middle of a path  
  mid arrow/.style={postaction={decorate,decoration={  
     markings,  
     mark=at position .5 with {\arrow[#1]{stealth}}  
    }}},  
 }  

As an exmaple, see:

 \begin{tikzpicture}[scale=2]  
 \clip (0.6,3.75) rectangle (3.85,0.85);  
 \draw[thick] (0,0) ellipse (3 and 3);  
 \draw[postaction={on each segment={mid arrow}}] (60:2) arc (60:30:2) -- (30:2.8) arc(30:60:2.8)--cycle;  
 \draw[postaction={on each segment={mid arrow}}] (30:4.2)arc (30:60:4.2) --(60:3.2)arc (60:30:3.2)--cycle;  
 \node at (1.745,1.795) {$L_1(r)$};  
 \node at (0.9,2.15) {$L_2(r)$};  
 \node at (1.225,1.2) {$L_3(r)$};  
 \node at (2.275,1) {$L_4(r)$};  
 \node at (2.5,2.425) {$T_1(r)$};  
 \node at (3.45,1.65) {$T_2(r)$};  
 \node at (3.225,3.125) {$T_3(r)$};  
 \node at (1.575,3.325) {$T_4(r)$};  
 \end{tikzpicture}  

No comments:

Post a Comment