# How to draw a closed curve with a flag-like path and attach some labels to them?

I'm trying to draw some arbitrary closed two dimensional curve where I'm focusing on only part of the boundary. I want to label the diameter of the part of the boundary I'm focusing on. Last, I'd like to put a tube encompassing this part of the boundary, and label both. Here is a picture of the situation I desire:

The symbols are $\Omega$, $\operatorname{diam} (\partial \varphi)$, $\operatorname{diam} (\mathcal{R}_i)$, and $\partial \phi^2$.

Any help would be greatly appreciated. I understand how to get one simple closed curve, but not two overlapping as in the picture above with two straight lines stretching as shown labeled above.

-
The hobby library may be useful in creating a nice-looking "arbitrary closed curve." – Charles Staats Nov 8 '13 at 22:25
@Charles Staats The hobby library? – Anthony Peter Nov 8 '13 at 22:29
please refer to this link : tex.ac.uk/ctan/graphics/pgf/contrib/hobby/hobby_doc.pdf. Hobby is a tikz library. – s__C Nov 8 '13 at 22:33
@s__C Could you help in constructing the desired diagram? – Anthony Peter Nov 8 '13 at 22:59
The tube edges are straight lines or curvy lines? – kiss my armpit Nov 8 '13 at 23:09

Thanks to Marienplatz for providing the coordinates

Using tikz and hobby. Code could have been minimized and refined, but let us be elaborative ;-)

\documentclass[tikz,margin=10pt]{standalone}
\usepackage{amsmath}
\usetikzlibrary{hobby}

\begin{document}

\begin{tikzpicture}[line width=1pt,line cap = round]
\node[fill=black,circle,inner sep=0pt,outer sep=0pt,label={[xshift=1pt]below right:$\partial \phi^2$}] at (0,1) (a) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (1,3) (b) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (4,4) (c) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (5,2) (d) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (4.5,.5) (e) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (4,0) (f) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (3,.2) (g) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (1,0) (h) {};

\path[draw,use Hobby shortcut,closed=true]
(a) .. (b) .. (c) .. (d) .. (e) .. (f) .. (g) .. (h);

\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (4.5,4.5) (i) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt] at (5,4.8) (j) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt,label={[xshift=4pt]below left:$\Omega$}] at (7.7,5.6) (k) {} ;
\node[fill=black,circle,inner sep=0pt,outer sep=0pt,xshift=1cm,yshift=-2cm] at (4.5,4.5) (l) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt,xshift=1cm,yshift=-2cm] at (5,4.8) (m) {};
\node[fill=black,circle,inner sep=0pt,outer sep=0pt,xshift=1cm,yshift=-2cm] at (7.7,5.6) (n) {};

\draw (c) to [quick curve through={(i) . . (j)}] (k)
(k) -- node[midway,below,sloped]{$\alpha$} (n)
(n) to [quick curve through={(m) . . (l)}] (d)
(m) -- node[midway,below,sloped]{$\operatorname{diam} (\mathcal{R}_i)$} (j)
(d) -- node[midway,below,sloped]{$\operatorname{diam} (\partial \varphi)$} (c);

\end{tikzpicture}

\end{document}


With lesser lines and edits for the comment:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{hobby}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[line width=.6pt,line cap = round,scale=.5,transform shape]

\foreach \x/\y/\z in {0/1/a,1/3/b,4/4/c,5/2/d,4.5/.5/e,4/0/f,3/.2/g,1/0/h}{
\coordinate (\z) at (\x,\y);
}
\foreach \x/\y/\z in {4.5/4.5/i,5/4.8/j,7.7/5.6/k}{
\coordinate (\z) at (\x,\y);
}
\foreach \x/\y/\z in {4.5/4.5/l,5/4.8/m,7.7/5.6/n}{
\coordinate[xshift=1cm,yshift=-2cm] (\z) at (\x,\y);
}

\path[draw,use Hobby shortcut,closed=true]
(a) .. (b) .. (c) .. (d) .. (e) .. (f) .. (g) .. (h);

\draw (c) to [quick curve through={(i) . . (j)}] (k)
(k) -- node[midway,left]{$\alpha$} (n)
(n) to [quick curve through={(m) . . (l)}] (d)
(m) -- node[midway,below,sloped]{$\operatorname{diam} (\mathcal{R}_i)$} (j)
(d) -- node[midway,below,sloped]{$\operatorname{diam} (\partial \varphi)$} (c);

\node[xshift=12pt,yshift=-5pt] at (a.-30) {$\partial \phi^2$};
\node[xshift=-3pt,yshift=-5pt] at (k.220) {$\Omega$};

\end{tikzpicture}
\caption{Some description for this figure}
\end{figure}

\end{document}


I have used scale=.5,transform shapein tikzpicture options to scale it down. Also added \alpha in the rightmost line.

-
Eh! What is the equivalent of \pstTranslation{C}{D}{C1,C2,C3} in tikz? – Harish Kumar Nov 9 '13 at 1:22
How would I scale it down? And add a $\alpha$ halfway down the rightmost line. (the one to the right of omega) – Anthony Peter Nov 9 '13 at 2:44
If you rotate the alpha so its horizontal, I'll accept your answer. – Anthony Peter Nov 9 '13 at 3:06
@AnthonyPeter That is easy. Change (k) -- node[midway,below,sloped]{$\alpha$} (n) to (k) -- node[midway,left]{$\alpha$} (n). See the edit. – Harish Kumar Nov 9 '13 at 3:16
much appreciated. – Anthony Peter Nov 9 '13 at 3:17

## Complete Code

The complete input files are given as follows.

diagram.tex

% let the name of this file be diagram.tex
% Compile it with
% latex diagram, followed by
% dvips diagram, followed by
% ps2pdf -dAutoRotatePages=/None diagram.ps (if you are using Windows, please replace = with #)
\documentclass[pstricks,border=3pt]{standalone}
\usepackage{pst-eucl}
\usepackage{amsmath}
\DeclareMathOperator{\diam}{diam}
\psset{PointName=none,PointSymbol=none,unit=.75,shortput=nab,nrot=:U}
\begin{document}
\begin{pspicture}[showgrid=false](8.7,5.6)
\pstGeonode
(0,1){A}
(1,3){B}
(4,4){C}
(5,2){D}
(4.5,.5){E}
(4,0){F}
(3,.2){G}
(1,0){H}
(4.5,4.5){C1}
(5,4.8){C2}
(7.7,5.6){C3}
\pstTranslation{C}{D}{C1,C2,C3}[D1,D2,D3]
\psccurve(A)(B)(C)(D)(E)(F)(G)(H)
\pscustom{\pscurve(C)(C1)(C2)(C3)\psline(D3)\pscurve(D2)(D1)(D)}
\ncline{C}{D}_{$\diam (\partial \varphi)$}
\ncline{C2}{D2}_{$\diam (\mathcal{R}_i)$}
\uput{6pt}[-110](C3){$\Omega$}
\uput{6pt}[-30](A){$\partial \phi^2$}
\end{pspicture}
\end{document}


Main.tex

% let the name of this file be main.tex
% compile it with
% pdflatex main (it needs compilation twice or more to make the cross references get properly linked)
% make sure diagram.pdf exists!
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{../../Diagrams/}}
\usepackage{lipsum,xcolor}% for dummy text and color, you might not need it in your production!
\begin{document}
\begin{figure}
\centering
\includegraphics[scale=1]{diagram}
\caption{Diagraming with PSTricks is always fun!}
\label{fig:diagram}
\end{figure}
\lipsum[1-4]
\textcolor{red}{See page~\pageref{fig:diagram}, there is a beautiful example of PSTricks there.}
\end{document}


Screenshot

Notes

## Diagram Management

• Every diagram should be composed in a single, separate, standalone input file. This approach will make your project becomes easier to maintain. It also allows you to reuse the diagrams for other projects. Use standalone document class to get a tight output so any excessive white spaces (excluding the intentionally added borders) will be trimmed.
• The recommended approach is to save the input file of each diagram in the same directory (named Diagrams, for example) and should be one at least 2 level higher than the individual project directory. See the directory structure below to illustrate the explanation better.

/other directory/
/other directory/my documents/
/other directory/my documents/Diagrams/
/other directory/my documents/Diagrams/Diagram1.tex/
/other directory/my documents/Diagrams/Diagram2.tex/
.
.
.
/other directory/my documents/Diagrams/Diagramn.tex/
/other directory/my documents/Projects/
/other directory/my documents/Projects/Project 1/Main.tex/
/other directory/my documents/Projects/Project 2/Main.tex/
.
.
.
/other directory/my documents/Projects/Project n/Main.tex/

• Compile each diagram containing PSTricks code with

latex filename
dvips filename
ps2pdf -dAutoRotatePages=/None filename.ps


For users with legacy Windows, replace = with #. Now we have PDF version for each diagram.

## Project Management

• Every project input file (named Main.tex, for example) should be in a separate project folder. It is also useful for easy maintenance.
• Compile the Main.tex with pdflatex Main.tex to get a PDF output. You need 2 or more compilations to make the cross-references get properly rendered or linked.
• Import the PDF diagrams from Main.tex using \includegraphics{<digram-name>} provided by graphicx package. Don't forget to set the \graphicspath{{../../Diagrams/},{other-path-if-any/}} right after \usepackage{graphicx}.
-
Very impressive – Anthony Peter Nov 9 '13 at 2:10
How would I scale it down? – Anthony Peter Nov 9 '13 at 2:14
Also how would I add a caption labeling it "Figure N.n : blah blah" – Anthony Peter Nov 9 '13 at 2:42
@AnthonyPeter: Sorry for lately responding. I was sleeping when you asked. See my update. – kiss my armpit Nov 9 '13 at 9:33
License fee paid through an upvote already ;-) – Harish Kumar Nov 9 '13 at 12:25