15

I'm trying to draw on LaTeX some steps of a demonstration of the Residue Theorem, and I wanted to explicitly show what are the contour and the poles that I'm using. Using the Tikz package, I was able to draw the contour and the poles, with the method shown below:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{positioning, arrows, decorations.markings, calc}

\begin{document}

\begin{tikzpicture}[>=stealth] % axis \draw -> -- (-3.6,4) node[above]{$\Im(z)$}; \draw -> -- (3,0) node[right]{$\Re(z)$};

    % irregular shape
    \draw  plot[smooth, tension=.9, very thick] coordinates {(-3.5,2.5) (-3,3.2) (-2.4, 3.3) (-1,3.7) (0,3.4) (2,3.9) (2.5,3.5) (3,2.5) (2.5,0.2) (0,0.7) (-3,0.2) (-3.5,2.5)}[postaction={decorate,
         decoration={markings,
         mark=between positions -3.5 and 3 step 0.25 with {\arrow{<};}}}];

    % poles
    \path[draw, postaction={decorate,
         decoration={markings,
         mark=between positions 0.2 and 1 step 0.33 with {\arrow{<};}}}] 
         (-2,1.3)  arc (0:360:0.4) --cycle;
    \path[draw, postaction={decorate,
         decoration={markings,
         mark=between positions 0.2 and 1 step 0.33 with {\arrow{<};}}}] 
         (0,2.5)  arc (0:360:0.4) --cycle;
    \path[draw, postaction={decorate,
         decoration={markings,
         mark=between positions 0.2 and 1 step 0.33 with {\arrow{<};}}}] 
         (1.9,1.7)  arc (0:360:0.4) --cycle;

\end{tikzpicture}

\end{document}

The only thing left to do is connect the contour with the poles inside it, like that

and I don't know how to do it. At first thought I considered manually trace the lines between the contour and the poles and erase the inner areas between two lines, but it looks like a lot of work for something that can be more simple. Is this the only way to do that or there is a more efficient way?

Bernard
  • 271,350

1 Answers1

17

Here is a solution that automates the process with the command \contour:

enter image description here

Each circle must be given a name. For convenience, I also used the \coordinate command for each of the poles. Then you must choose, for each pole, a coordinate outside the main shape. The contours will be drawn parallel to the line from the external point to the corresponding pole.

For example, \contour{e1}{p1}{circle1}; will create the contour around the pole (p1) by intersecting two parallel lines with circle1 and the irregular shape, which I named mainshape.

The distance between the parallel lines is controlled globally by \conw

Four intersection points are calculated (i1) and (i2) form the inward path; (i3) and (i4) form the outward path. First small arcs of mainshape and the circle are "erased" by drawing very thick white lines over them. Note: If your background color isn't white you will need to change this. Then the parallel lines are drawn with arrows.

Note: I changed the mark positions of your irregular shape. They were preventing the code from compiling properly.

Here is the code:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{positioning, arrows, decorations.markings, calc, intersections}

\newcommand{\conw}{.05} \newcommand{\contour}[3]{\coordinate (uu) at ($(#1)!1cm!(#2)-(#1)$); % unit vector from e1 to p1 \path[name path=line2] let \p0=(uu), \p1=(#1), \p2=(#2) in (\x1+\y0\conw,\y1-\x0\conw)--(\x2+\y0\conw,\y2-\x0\conw); \path[name path=line1] let \p0=(uu), \p1=(#1), \p2=(#2) in (\x1-\y0\conw,\y1+\x0\conw)--(\x2-\y0\conw,\y2+\x0\conw); \path[name intersections={of=line1 and mainpath, by={i1}}, name intersections={of=line1 and #3, by={i2}}, name intersections={of=line2 and #3, by={i3}}, name intersections={of=line2 and mainpath, by={i4}}]; \drawvery thick,white--(i4); \drawvery thick,white--(i3); \begin{scope}[decoration={markings, mark=at position 0.5 with {\arrow{>}}}] \drawline cap=round, postaction={decorate}--(i2); \drawline cap=round, postaction={decorate}--(i4); \end{scope} }

\begin{document}

\begin{tikzpicture}[>=stealth]

    % axis
    \draw [->](-3.6,-0.4) -- (-3.6,4) node[above]{$\Im(z)$};
    \draw [->](-4,0) -- (3,0) node[right]{$\Re(z)$};

    % irregular shape
    \draw[name path=mainpath] plot[smooth, tension=.9, very thick] coordinates {(-3.5,2.5) (-3,3.2) (-2.4, 3.3) (-1,3.7) (0,3.4) (2,3.9) (2.5,3.5) (3,2.5) (2.5,0.2) (0,0.7) (-3,0.2) (-3.5,2.5)}[postaction={decorate,
         decoration={markings,
         mark=between positions 0.05 and 1 step 0.25 with {\arrow{<};}}}];

    % poles
    \coordinate(p1) at (-2.4,1.3);
    \coordinate(p2) at (-.4,2.5);
    \coordinate(p3) at (1.5,1.7);
    \path[name path= circle1, draw, postaction={decorate,
         decoration={markings,
         mark=between positions 0.2 and 1 step 0.33 with {\arrow{<};}}}] 
         (-2,1.3)  arc (0:360:0.4) --cycle;
    \path[name path= circle2, draw, postaction={decorate,
         decoration={markings,
         mark=between positions 0.2 and 1 step 0.33 with {\arrow{<};}}}] 
         (0,2.5)  arc (0:360:0.4) --cycle;
    \path[name path= circle3, draw, postaction={decorate,
         decoration={markings,
         mark=between positions 0.2 and 1 step 0.33 with {\arrow{<};}}}] 
         (1.9,1.7)  arc (0:360:0.4) --cycle;

    % contours
    \coordinate(e1) at (-4,3);
    \coordinate(e2) at (-1,4);
    \coordinate(e3) at (1,0);
    \contour{e1}{p1}{circle1};
    \contour{e2}{p2}{circle2};
    \contour{e3}{p3}{circle3};

\end{tikzpicture}

\end{document}

Sandy G
  • 42,558