TIKZ 中的 3D 体积

TIKZ 中的 3D 体积

在此处输入图片描述

我需要在三维空间中的任何函数下方制作正方形底部体积。可以是任何函数。我需要帮助才能开始这项工作。图片很糟糕,但这就是想法。

答案1

tikz-3dplot软件包允许您以 3D 形式绘制事物并执行正交投影。

\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);}
 \path[opacity=0.3,left color=blue,right color=blue,middle color=blue!20,shading
  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;
 \path[opacity=0.3,left color=blue,right color=blue,middle color=blue!20,shading
  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}

在此处输入图片描述

您可能希望将参数存储在 pgf 键中。

\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);}
 \path[opacity=0.3,left color=blue,right color=blue,middle color=blue!20,shading
  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;
 \path[opacity=0.3,left color=blue,right color=blue,middle color=blue!20,shading
  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}

在此处输入图片描述

答案2

在此处输入图片描述

为了帮助您入门:

\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}

相关内容