# Applying functions to curves in TikZ

I am trying to replicate this picture in TikZ

So far I have been able to recreate everything in the XY-plane. The only thing that bothers me now is the graph of the function itself. The domain is a simple closed smooth curve and now I would like to apply the function to this curve (if at all possible) to get the outline of the graph. Doing something similar with a coordinate grid in the XY-plane will solve the lines running over the graph. This is the only conceptual hurdle remaining for me. Is something like this possible? Can you apply a function to a curve in TikZ? At the moment my code consists of

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[y={(0.6495cm, 0.375cm)}, x={(0.981cm,-0.191cm)}, z={(0cm, 1cm)}]
\draw[->] (0,0,0) -- (6.3,0,0) node[anchor=west] {$X$};
\draw[->] (0,0,0) -- (0,5.5,0) node[anchor=south west] {$Y$};
\draw[->] (0,0,0) -- (0,0,5) node[anchor=south] {$Z$};
\node[shape=coordinate] (p1) at (3.6,0.7,0) {};
\node[shape=coordinate] (p2) at (2.3,1.4,0) {};
\node[shape=coordinate] (p3) at (1.4,1,0) {};
\node[shape=coordinate] (p4) at (0.9,1.8,0) {};
\node[shape=coordinate] (p5) at (2.1,3.3,0) {};
\node[shape=coordinate] (p6) at (4.65,1.9,0) {};
\filldraw[line width=1pt, fill=lightgray, tension=0.9] plot[smooth cycle] coordinates{(p1) (p2) (p3) (p4) (p5) (p6)};
\end{tikzpicture}
\end{document}


This is the current output

• Have you considered using a plotting package - pgfplots. I am not 100% sure that your specific plot can be done, but I think so. There are many advantages by using a package - you do not have to draw the axis your self - that means that you consistent can add tick marks, labels, legends, ... See e.g. pgfplots.net/tikz/examples/contour-and-surface and the manual. Commented Aug 25, 2017 at 9:33
• You probably need to do some external data generation (that's how I've done it with a similar plot). I've made the 3d curves via python, by first getting the data for the lines in the xy domain. Then applying f to those xy straight lines. This generates xyz data for each 3d curve, which can then be easily plotted using pgfplots. Commented Aug 25, 2017 at 9:44
• This is a very nice picture to try to replicate. May I ask where you found it? Commented Oct 1, 2017 at 13:31
• @MarkTwain It appeared in the notes of a multivariable calculus course. I contacted my professor and he told me he used pstricks to generate the figure. However, my strengths lie in TikZ and I don't feel the need to learn a second tool for creating figures. Commented Oct 23, 2017 at 9:35

Here is a solution, I am not completely satisfied but it looks like the figure requested

Note the use of global variable in the foreach loop and scope to shift the curve

What I have not managed to do is to plot from curve C1 to curve C2, Tikz does not recognize the curve in the 1st scope!

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,intersections,calc}
\begin{document}
\begin{tikzpicture}[y={(0.6495cm, 0.375cm)}, x={(0.981cm,-0.191cm)}, z={(0cm, 1cm)}]
\draw[->] (0,0,0) -- (6.3,0,0) node[anchor=west] {$X$};
\draw[->] (0,0,0) -- (0,5.5,0) node[anchor=south west] {$Y$};
\draw[->] (0,0,0) -- (0,0,5) node[anchor=south] {$Z$};
\begin{scope}
\node[shape=coordinate] (p1) at (3.6,0.7,0) {};
\node[shape=coordinate] (p2) at (2.3,1.4,0) {};
\node[shape=coordinate] (p3) at (1.4,1,0) {};
\node[shape=coordinate] (p4) at (0.9,1.8,0) {};
\node[shape=coordinate] (p5) at (2.1,3.3,0) {};
\node[shape=coordinate] (p6) at (4.65,1.9,0) {};
\filldraw[line width=1pt, fill=lightgray, tension=0.9] plot[smooth cycle,,name path global/.expanded=C2] coordinates{(p1) (p2) (p3) (p4) (p5) (p6)};
\end{scope}

\begin{scope}[shift={(0,0,4)}]
\node[shape=coordinate] (p1) at (3.6,0.7,0) {};
\node[shape=coordinate] (p2) at (2.3,1.4,0) {};
\node[shape=coordinate] (p3) at (1.4,1,0) {};
\node[shape=coordinate] (p4) at (0.9,1.8,0) {};
\node[shape=coordinate] (p5) at (2.1,3.3,0) {};
\node[shape=coordinate] (p6) at (4.65,1.9,0) {};
\filldraw[line width=1pt, fill=yellow, tension=0.9,name path global/.expanded=C1] plot[smooth cycle] coordinates{(p1) (p2) (p3) (p4) (p5) (p6)};
\end{scope}

\foreach \xx in {21,26,...,60}{
\path[name path global/.expanded=D\xx] ({\xx/10},0,0) --++(0,0,5);
}

\foreach \xx in {21,26,...,60}{
\path [name intersections/.expanded={of={D\xx} and {C1},by=c\xx}];
\draw[thick,red] (c\xx) --++(0,0,-4);
}

\end{tikzpicture}

\end{document}


• salut hpekristiansen pourquoi as-tu supprimé le texte en français? Commented Aug 25, 2017 at 10:14
• English is the only allowed language on all Stack Exchange sites. It is not needed or wished for to repeat everything twice in a second language. No one is demanding perfect english, so most people can participate by using auto translation. meta.stackexchange.com/questions/13676/… Commented Aug 26, 2017 at 7:02