# How to draw arbitrary closed surface with TikZ?

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

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.

-
Welcome at Tex.sx! Your request is kind of vague. Are you interested in surface plots defined by data matrizes and/or functional expressions in general? Then you may want to browse the questions under the "Related" section of your question. Or are you interested in schematic figures were the only requirement is that it should look "like a cloud", possibly enriched with annotations? Your figure appears to belong to a schematic explanation (and not a precily defined surface plot). –  Christian Feuersänger Jul 6 '13 at 22:28
I want to schematic figures, like a cloud. Arbitrary surface, not defined surface plots. I know, it can be done with using "controls" but i can not closed the lines or bends. Thank you for your interesting. –  ferahfeza Jul 6 '13 at 22:35
Welcome to TeX.SX! Generally, we can't do much with 'just a picture' -- this figure was quite apparently TeX'd; do you have the source to this figure? It will help us generalize it into what you need. Would you add a minimal working example (MWE) (from \documentclass to \end{document}? :) –  Sean Allred Jul 7 '13 at 1:51
I have updated my question. –  ferahfeza Jul 7 '13 at 10:15
For arbitrary closed shapes you might find useful the [hobby](www.ctan.org/pkg/hobby) package. You find an couple of examples here and here. –  Claudio Fiandrino Jul 8 '13 at 14:57

## 1 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}


-
@ JLDiaz, Thank you very muck. This will be my starting point. –  ferahfeza Jul 7 '13 at 11:54