[Tex/LaTex] How to represent the curved shape of a surface

pgfplotstikz-pgf

surface

How can I give third dimension to the green surface, with shadings of color or light effects, using tikz or pgfplots?

The matter is that the green surface looks (is) flat as the red one, while I would like it to look like the plot of an arbitrary real function of two variables (over the domain in red). This is why I also would not mind pgfplots.

It does not really matter to see axes in transparency or not.

My latest code in Addendum 2.

Addendum

Consider the following picture:

image 2

I would like my green surface to look like the blue one in this latter. I see that the blue surface has a different contour line than the orange one (it is not the same closed curve translated only) and this help rendering "volume". But to change this would not be a problem to me: I would like to understand instead how to shade the green surface in my picture the same way the blue one is in the second image.

This second picture is not as good as we can do with TikZ/PGF, but I think the shade of blue is shaped properly to give the idea of curvature. This is what I want to achieve, with any syntax.

Addendum (2)

The following is the best I could do so far (shading method is very weak…).

image 3

\documentclass[border=5mm,tikz=true]{standalone}

\usepackage{tikz,pgfplots}

\usetikzlibrary{decorations.shapes}

\begin{document}

\begin{tikzpicture}[scale=1.25]
\draw [dotted, fill=green!15] plot [smooth cycle] %
    coordinates {(-1.14,-1)(-0.84, -.18) (-0.04, 0.3) (2.24, 0) %
    (4.48, -0.56) (4.48, -1.46) (3.38,-1.84)(0.38, -1.28)};
\draw [dotted, fill=red!15] plot [smooth cycle] %
    coordinates {(-1.04, 1.54) (-0.52, 2.66) (1.22, 3.22) %
    (4.48, 2.1)(4.44, 1.14) (3.38, 0.98) (0.84, 2.26)};
%\shadedraw [color=red!15, inner color=red!5, outer color=red!15] (1,3) circle (2mm);
\draw [dotted, fill=red!15] plot [smooth cycle] %
    coordinates {(-1.04, 1.54) (-0.52, 2.16) (1.22, 2.72) %
    (4.48, 2.1)(4.44, 1.14) (3.38, 0.98) (0.84, 2.26)};
\draw[thick,->] (0,0) -- (-2,-1.5) node[below] {$x$};
\draw[thick,->] (0,0) -- (5,0) node[right] {$y$};
\draw[thick,->] (0,0) -- (0,3) node[above] {$z$};
\filldraw (4.2,3.2) node[left] {$z=f(x,y)$};
\draw [dashed] (3.2,-1) -- (3.2,1.1);
\draw [dashed, lightgray] (3.2,1.1) -- (3.2,2.2);
\filldraw (3.2,-1)circle (2pt) node[left] {$\left(x_0,y_0\right)$};
\filldraw (3.2,2.2)circle (2pt) node[left] % 
    {$\left(x_0,y_0,f\left(x_0,y_0\right)\right)$};
\end{tikzpicture}

\end{document}

I'll post updates, thank you for any hint.

Best Answer

Here's an hackish suggestion. Not very general, not very nice but does the job in a quick and dirty way. The alternative seems to specify the surface by hand and compute the "shadow" so that the drawinf is accurate. I think the key graphical feature to render the 3D structure of the surface is to draw its grid, which is done here by the shader.

Here I just clip with a 2D area the 3D drawing to give the illusion of a "random" border. The original surface is taken from here.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, filecontents}

\begin{filecontents*}{filename.txt}
0 0 1.36
1 0 1.50
2 0 1.60
3 0 1.69
4 0 1.77
5 0 1.80
6 0 1.76
7 0 1.68
8 0 1.58
9 0 1.41
10 0 1.24

0 1 1.46
1 1 1.60
2 1 1.73
3 1 1.83
4 1 1.92
5 1 1.97
6 1 1.95
7 1 1.86
8 1 1.73
9 1 1.55
10 1 1.37

0 2 1.54
1 2 1.69
2 2 1.84
3 2 1.97
4 2 2.07
5 2 2.12
6 2 2.11
7 2 2.02
8 2 1.87
9 2 1.68
10 2 1.49

0 3 1.56
1 3 1.74
2 3 1.92
3 3 2.07
4 3 2.18
5 3 2.25
6 3 2.24
7 3 2.14
8 3 1.99
9 3 1.80
10 3 1.59

0 4 1.56
1 4 1.74
2 4 1.96
3 4 2.13
4 4 2.25
5 4 2.32
6 4 2.31
7 4 2.22
8 4 2.07
9 4 1.86
10 4 1.63

0 5 1.56
1 5 1.74
2 5 1.95
3 5 2.14
4 5 2.27
5 5 2.34
6 5 2.33
7 5 2.24
8 5 2.09
9 5 1.88
10 5 1.64

0 6 1.52
1 6 1.71
2 6 1.92
3 6 2.09
4 6 2.22
5 6 2.29
6 6 2.28
7 6 2.20
8 6 2.06
9 6 1.87
10 6 1.65

0 7 1.45
1 7 1.66
2 7 1.85
3 7 2.00
4 7 2.11
5 7 2.18
6 7 2.18
7 7 2.11
8 7 1.98
9 7 1.80
10 7 1.61

0 8 1.37
1 8 1.56
2 8 1.73
3 8 1.87
4 8 1.97
5 8 2.04
6 8 2.04
7 8 1.98
8 8 1.87
9 8 1.71
10 8 1.55

0 9 1.29
1 9 1.41
2 9 1.57
3 9 1.72
4 9 1.82
5 9 1.87
6 9 1.87
7 9 1.83
8 9 1.74
9 9 1.62
10 9 1.47

0 10 1.17
1 10 1.25
2 10 1.41
3 10 1.55
4 10 1.65
5 10 1.70
6 10 1.70
7 10 1.66
8 10 1.58
9 10 1.48
10 10 1.34
\end{filecontents*}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[view={-20}{20}, grid=both, xmin=0, ymin=0, zmin=0]

      \clip[
          rounded corners=5,
          x=1.1cm,y=.4cm,z=3cm,
          yshift=.1cm, xshift=-.7cm
      ]
          (.3,2) -- (0,1) -- (.5,.3) -- (1,.2) -- (2,1.3) -- (3.5,.5) --
          (4.5,2) -- (3.5,3) -- (1.5,3.4) -- (1.5,2.5) --
          cycle
          [yshift=2.7cm]
          (.3,2) -- (0,1) -- (.5,.3) -- (1,.2) -- (2,1.3) -- (3.5,.5) --
          (4.5,2)
          [rounded corners=0]
          parabola[parabola height=1.1cm] cycle
      ;

      \addplot3[surf] file {filename.txt};
      \addplot3[surf, point meta=explicit] table [z expr=0, meta index=2] {filename.txt};

    \end{axis}
  \end{tikzpicture}
\end{document}

preview