# 3D Volume in TIKZ

I need to make the square base volume below any function in a three-dimensional space. It can be any function. I need help getting this job started. The image is bad, but that's the idea.

• Welcome to TeX.SE! What have you tried so far? – Mensch May 3 at 0:55
• I'm voting to close this question as off-topic because this is a just-do-it-for-me question. – Raaja May 3 at 14:17
• @Raaja The problem is that there are too many kind and generous people ready to help :) – Anush May 3 at 15:10
• @Anush Ofc yes, but that not how the site dynamics is supposed to be per se. – Raaja May 3 at 15:47

The tikz-3dplot package allows you to draw things in 3d and perform orthographic projections.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[tdplot_main_coords,>=stealth,declare function={%
pfft(\x)=pi+0.3*sin(deg(\x));}]
\draw[->] (0,0,0) coordinate (O) -- (5,0,0) coordinate(X) node[pos=1.1]{$x$};
\draw[->] (O) -- (0,5,0) node[pos=1.1]{$y$};
\draw[->] (O) -- (0,0,5) node[pos=1.1]{$z$};
\draw[thick] plot[variable=\x,domain=0.8*pi:1.1*pi,smooth] (2.2,\x,{pfft(2*\x)})
coordinate (T1)--
plot[variable=\x,domain=1.1*pi:0.8*pi,smooth] (0.8,\x,{pfft(2*\x)}) coordinate
(T3)-- cycle;
\draw (2.2,0.8*pi,0) coordinate (B4)-- (2.2,1.1*pi,0) coordinate (B1)
-- (0.8,1.1*pi,0) coordinate (B2) -- (0.8,0.8*pi,0) coordinate (B3) -- cycle;
\path (2.2,0.8*pi,{pfft(2*0.8*pi)}) coordinate (T4)
(0.8,1.1*pi,{pfft(2*1.1*pi)}) coordinate (T2);
\foreach \X in {1,...,4}
{\draw (B\X) -- (T\X);}
angle=72]
plot[variable=\x,domain=0:1.1*pi,smooth] (3,\x,{pfft(2*\x)}) --
plot[variable=\x,domain=1.1*pi:0,smooth] (0,\x,{pfft(2*\x)}) -- cycle;
angle=72]
plot[variable=\x,domain=1.1*pi:2.2*pi,smooth] (3,\x,{pfft(2*\x)}) --
plot[variable=\x,domain=2.2*pi:1.1*pi,smooth] (0,\x,{pfft(2*\x)}) -- cycle;
\draw plot[variable=\x,domain=0:2.2*pi,smooth] (3,\x,{pfft(2*\x)}) --
plot[variable=\x,domain=2.2*pi:0,smooth] (0,\x,{pfft(2*\x)}) -- cycle;
\end{tikzpicture}
\end{document}


You may want to store the parameters in pgf keys.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{110}
\foreach \X in {0,...,35}
{\pgfmathsetmacro{\Objymax}{{1.6*pi+0.5*sin(10*\X)*pi}}
\begin{tikzpicture}[tdplot_main_coords,>=stealth,declare function={%
pfft(\x)=2+0.3*sin(deg(\x));},/tikz/3D surface/.cd,
ymin/.initial=0,ymax/.initial=2.2*pi,xmin/.initial=1,xmax/.initial=4,
/tikz/3D object/.cd,
ymin/.initial=0.8*pi,ymax/.initial=\Objymax,xmin/.initial=1.8,xmax/.initial=3.2]
\draw[->] (0,0,0) coordinate (O) -- (5,0,0) coordinate(X) node[pos=1.1]{$x$};
\draw[->] (O) -- (0,5,0) node[pos=1.1]{$y$};
\draw[->] (O) -- (0,0,5) node[pos=1.1]{$z$};
\draw[thick] plot[variable=\x,domain=\pgfkeysvalueof{/tikz/3D object/ymin}:\pgfkeysvalueof{/tikz/3D object/ymax},smooth]
(\pgfkeysvalueof{/tikz/3D object/xmax},\x,{pfft(2*\x)})
coordinate (T1)--
plot[variable=\x,domain=\pgfkeysvalueof{/tikz/3D object/ymax}:\pgfkeysvalueof{/tikz/3D object/ymin},smooth]
(\pgfkeysvalueof{/tikz/3D object/xmin},\x,{pfft(2*\x)}) coordinate
(T3)-- cycle;
\draw (\pgfkeysvalueof{/tikz/3D object/xmax},\pgfkeysvalueof{/tikz/3D object/ymin},0) coordinate (B4)--
(\pgfkeysvalueof{/tikz/3D object/xmax},\pgfkeysvalueof{/tikz/3D
object/ymax},0) coordinate (B1)
-- (\pgfkeysvalueof{/tikz/3D object/xmin},\pgfkeysvalueof{/tikz/3D object/ymax},0) coordinate (B2) -- (\pgfkeysvalueof{/tikz/3D object/xmin},\pgfkeysvalueof{/tikz/3D object/ymin},0) coordinate (B3) -- cycle;
\path (\pgfkeysvalueof{/tikz/3D object/xmax},\pgfkeysvalueof{/tikz/3D object/ymin},{pfft(2*\pgfkeysvalueof{/tikz/3D object/ymin})}) coordinate (T4)
(\pgfkeysvalueof{/tikz/3D object/xmin},\pgfkeysvalueof{/tikz/3D
object/ymax},{pfft(2*\pgfkeysvalueof{/tikz/3D object/ymax})}) coordinate (T2);
\foreach \X in {1,...,4}
{\draw (B\X) -- (T\X);}
angle=72]
plot[variable=\x,domain=\pgfkeysvalueof{/tikz/3D surface/ymin}:{(\pgfkeysvalueof{/tikz/3D
surface/ymax}+\pgfkeysvalueof{/tikz/3D surface/ymin})/2},smooth]
(\pgfkeysvalueof{/tikz/3D surface/xmax},\x,{pfft(2*\x)}) --
plot[variable=\x,domain={(\pgfkeysvalueof{/tikz/3D
surface/ymax}+\pgfkeysvalueof{/tikz/3D surface/ymin})/2}:\pgfkeysvalueof{/tikz/3D surface/ymin},smooth] (\pgfkeysvalueof{/tikz/3D surface/xmin},\x,{pfft(2*\x)}) -- cycle;
angle=72]
plot[variable=\x,domain={(\pgfkeysvalueof{/tikz/3D
surface/ymax}+\pgfkeysvalueof{/tikz/3D surface/ymin})/2}:\pgfkeysvalueof{/tikz/3D surface/ymax},smooth]
(\pgfkeysvalueof{/tikz/3D surface/xmax},\x,{pfft(2*\x)}) --
plot[variable=\x,domain=\pgfkeysvalueof{/tikz/3D surface/ymax}:{(\pgfkeysvalueof{/tikz/3D
surface/ymax}+\pgfkeysvalueof{/tikz/3D surface/ymin})/2},smooth]   (\pgfkeysvalueof{/tikz/3D surface/xmin},\x,{pfft(2*\x)}) -- cycle;
\draw plot[variable=\x,domain=\pgfkeysvalueof{/tikz/3D surface/ymin}:\pgfkeysvalueof{/tikz/3D surface/ymax},smooth]
(\pgfkeysvalueof{/tikz/3D surface/xmax},\x,{pfft(2*\x)}) --
plot[variable=\x,domain=\pgfkeysvalueof{/tikz/3D surface/ymax}:\pgfkeysvalueof{/tikz/3D surface/ymin},smooth]
(\pgfkeysvalueof{/tikz/3D surface/xmin},\x,{pfft(2*\x)}) -- cycle;
\end{tikzpicture}}
\end{document}


\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[x={(210:1cm)},y={(0:1cm)},z={(90:1cm)}]
\draw (0,0,0) -- (3,0,0) -- (3,3,0)--(0,3,0)--cycle;
\draw (3,0,0) -- (3,0,4) .. controls (3,1,3.5) and (3,2,3) .. (3,3,3) -- (3,3,0);
\draw (3,3,3) .. controls (2,3,3) and (1,3,5) .. (0,3,5)--(0,3,0);
\draw (0,3,5) .. controls (0,2,4) and (0,1,4) .. (0,0,4)--(0,0,0);
\draw (0,0,4) -- (3,0,4);
\end{tikzpicture}
\end{document}