Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
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
1  
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
add comment

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
@ JLDiaz, Thank you very muck. This will be my starting point. –  ferahfeza Jul 7 '13 at 11:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.