2

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

enter image description here

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}

3 Answers3

1

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

enter image description here

\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!

enter image description here

\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)
;
Black Mild
  • 17,569
  • 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! – Subhajit Paul Jun 30 '21 at 07:21
1

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:

fill clip smooth curve

\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.

SebGlav
  • 19,186
0

Is it what you're looking for?

even odd rule hobby

\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}

SebGlav
  • 19,186