Convex set picture

tikz-pgf

I'm trying to do this:

enter image description here

This is my attempt:

\documentclass[12pt,a4paper]{book}

\usepackage{tikz}

\usetikzlibrary{calc, shadings} 

\usetikzlibrary{positioning,arrows.meta}

\begin{document}

\begin{tikzpicture}

\pgfmathsetmacro{\myslope}{atan2(2,-4.5)}

\draw[fill=gray!30] (M) to[out=\myslope,in=0] ++ (-2,0.5) to[out=180,in=90] ++ (-1,-0.5)

 to[out=-90,in=90] ++ (2,-2) to[out=-90,in=90] ++ (-3,-1)

 to[out=-90,in=180] ++(4,-1) to[out=0,in=\myslope+180] cycle;

\end{tikzpicture}

\end{document}

Can you help me?

Best Answer

enter image description here

\documentclass[12pt]{book}
\usepackage{caption, subcaption}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                bbox}

\begin{document}
    \begin{figure}[ht]
    \centering
    \captionsetup[subfigure]{labelformat=simple}
    \renewcommand\thesubfigure{}
\subfloat[][Convex set]%
{
    \begin{tikzpicture}[bezier bounding box]
\draw[fill=gray!30] 
    (0,0) .. controls +(0,3) and + (0,2) .. (5,1)
          .. controls +(0,-3) and + (0,-2) .. 
          cycle;
\draw[Circle-Circle]  
    (1,-0.2)    node[above] {$x_1$} -- ++ (3,1)
                node[above] {$x_2$};
\end{tikzpicture}
}
\hfil
\subfloat[][Non-convex set]%
{
    \begin{tikzpicture}[bezier bounding box]
\draw[fill=gray!30]
    (0,0) .. controls +(0,4) and + (-1,0) .. (3,1)
          .. controls +(1,0) and + ( 0,2) .. (5,0)
          .. controls +(0,-2) and + (1,0) .. (2,0)
          .. controls +(-1,0) and + (0,-2) ..
          cycle;
\draw[Circle-Circle]
    (1,-0.2)    node[above] {$x_1$} -- ++ (3,0)
                node[above] {$x_2$};
\end{tikzpicture}
}
    \end{figure}
\end{document}

TikZ library bbox is available on CTAN.