[Tex/LaTex] How to draw arbitrary closed surface with TikZ

tikz-pgf

I want to draw an arbitrary closed surface like following figure.
How can i do it?
enter image description here

Here is the MWE:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shade[line width=2pt, color=blue] (0, 0) .. controls(1,2) .. (3, 0) ;
\end{tikzpicture}
\end{document}

In my code, color option doesn't work and I can't close the \controls.

Best Answer

When you try to shade or fill a path, TikZ closes it indeed, but the last segment which closes it is a straight line.

If you want a "rounded" closed path, you have to make the path end at the same point it started, and control the curvature so that it is "smooth" at that point.

Doing so with control points is difficult. I would use the hobby package, which provides metapost-like syntax to specify smooth curved paths (both open and closed), and that it is highly recommendable if you want control over the final shape.

If you don't need too much control, but instead any "rounded shape" would be enough, you can use the construct to [in=alpha, out=beta] to specify the angles alpha and beta at which the curved path leaves its start and enters its end, respectively. If you use the same construct to conect each pair of points, and ensure that the curve leaves the point at the same angle (+180) that it entered it, you'll get smooth curve also at those points.

For example:

\begin{tikzpicture}
\shade[line width=2pt, top color=blue] 
  (0, 0) to [out=20, in=70]   (3,0)
         to [out=250, in=200] (0,0) ; 
\fill[red] (0,0) circle(2pt) (3,0) circle(2pt); % Show points
\end{tikzpicture}

Example