# How to use 'controls' with closed curves like 'circle' or 'ellipse' to produce irregular closed curves

Preparing a lecture note for Topology requires a lot of blob-like (irregular) closed loop diagrams. Unfortunately, I do not know an easy way to do that frequently. I happened to have this idea about the possibility of using controls on the existing library closed curves like circle, ellipse, etc. Please enlighten me if that is actually a feasible possibility. I want to write the code like

\draw (0,0) .. controls (-1,0) and (1,0) .. circle (2);


to produce a curve which may look like

EDIT:

Surfing in TeX.SE, I found this answer. But this brings another problem, the tikzfillbetween is not working as intended. See the following MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{hobby, pgfplots.fillbetween}
\begin{document}
\begin{tikzpicture}[use Hobby shortcut,closed=true]
\draw [name path=A] (-3.5,0.5) .. (-3,2.5) .. (-1,3.5).. (1.5,3).. (4,3.5).. (5,2.5).. (5,0.5) ..(2.5,-2).. (0,-0.5).. (-3,-2).. (-3.5,0.5);
\draw [name path=B] (0,0) circle (1);
\tikzfillbetween [of=A and B] {blue, opacity=0.2};
\end{tikzpicture}
\end{document}

• You might check out the hobby package. Jun 29 at 20:57
• @CharlesStaats I did. Please see my edit. Jun 29 at 21:09
• I do not understand what you try to do!? Does this answer your question: tex.stackexchange.com/a/33610/8650 Jun 29 at 21:23
• You just changed the topic of your question while we were trying to answer it :/ Jun 29 at 21:24
• @hpekristiansen It does, but with too much complexities! I want an easy way to generate closed curves. And I do not need that level of precision. Jun 29 at 21:38

OK, so instead of editing my previous answer (which was meant to give a hint on even odd rule with hobby closed curve, when the question was very unclear), I add a new one which I would delete if it's not what OP wants.

So basically, what you seem to ask for is a way to fill a clipped part of a shape, like the following:

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}
\def\A{(0,0) (1,1) (3,0) (2,-1)}
\def\B{(0,0) circle (1)}

\begin{scope}
\clip\B;
\fill[pattern=north west lines, pattern color=orange] plot[smooth cycle] coordinates {\A};
\end{scope}

\draw[violet]\B;
\draw[red] plot[smooth cycle] coordinates {\A};

\end{tikzpicture}
\end{document}


Since you said that the shape isn't relevant, I just made a short coded one, now you can customize it.

• Thank you. This is exactly I wanted. I realise that it cannot be easier than this. Jun 30 at 18:58
• Cool. And thanks again if you decide to upvote the answer too ;) Jun 30 at 20:43

How about using smooth cycle with try-and-error points like this?

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw plot[smooth cycle] coordinates{
(-1.8,-.2) (-1.6,.5) (-1,.9)
(-.3,1) (1,.7) (2,.2) (2.22,0)
(2.42,-.45) (2.25,-1)
(1.8,-1.18) (1.2,-1)
(0,-.8)
(-.9,-.9) (-1.5,-.7)
};
\draw
(-1.55,.3) circle(.7) +(190:1) node{$W_1$}
(-.18,-.68) circle(.7) +(-45:1) node{$W_2$};

\path[nodes={fill,circle,inner sep=0,outer sep=1pt,minimum size=3pt}]
(-1.95,.55) node (x1) {}
(-1.2,.5) node (x2) {}
(-.3,-.4) node (x3) {}
;
\draw[stealth-] (x1) to[out=85,in=-60] ++(100:.6) node[above]{$x$};
\draw[stealth-] (x2) to[out=85,in=-60] ++(100:.6) node[above]{$x$};
\path (2.1,.4) node{$U$}
(x3)+(0:.2) node{$y$};
\end{tikzpicture}
\end{document}


With hobby library, the curve is smoother!

\usetikzlibrary{hobby}
\draw[red,use Hobby shortcut,closed=true]
(-1.8,-.2) .. (-1.6,.5) .. (-1,.9) ..
(-.3,1) .. (1,.7) .. (2,.2) .. (2.22,0) ..
(2.42,-.45) .. (2.25,-1) ..
(1.8,-1.18) .. (1.2,-1) ..
(0,-.8) ..
(-.9,-.9) .. (-1.5,-.7)
;

• Thank you for your answer. Consolidating your answer with comments from hpekristiansen and Andrew Stacey, I am able to generate the intended diagram. But my concern was a little different. I do not need this much particularity in the diagram. Any generic closed irregular shape would serve my purpose. Since I have to generate a lot of them, I am looking for something simpler. It seems I could not express myself properly in the question. My apologies! Jun 30 at 7:21

Is it what you're looking for?

\documentclass[tikz]{standalone}
\usetikzlibrary{hobby}

\begin{document}
\begin{tikzpicture}[use Hobby shortcut,closed=true]
\fill[even odd rule,cyan] (-3.5,0.5) .. (-3,2.5) .. (-1,3.5).. (1.5,3).. (4,3.5).. (5,2.5).. (5,0.5) ..(2.5,-2).. (0,-0.5).. (-3,-2).. (-3.5,0.5)
(0,0) circle (1);
\end{tikzpicture}
\end{document}

• Actually, the opposite fill! Jun 29 at 21:39
• I wanted to draw something like this. Jun 29 at 21:53
• \draw [clip] (-3.5,0.5) .. (-3,2.5) .. (-1,3.5).. (1.5,3).. (4,3.5).. (5,2.5).. (5,0.5) ..(2.5,-2).. (0,-0.5).. (-3,-2).. (-3.5,0.5); \fill (0,0) circle (1); Jun 29 at 21:59
• @hpekristiansen Thank you. Please see my comment in the above answer. Jun 30 at 7:22
• You should have provided this picture in the first place. So that's way easier, just use clip, but with hobby, the result is not really convincing. Jun 30 at 17:14