繪製懸停在集合上的碗形 3D 函數

繪製懸停在集合上的碗形 3D 函數

我想知道是否有任何簡單的方法來繪製在集合(其域)上定義的 3D 函數。域將被繪製為“平”在地面上,而函數將被繪製為“懸停”在域之上。我正在考慮下面兩個例子:

在此輸入影像描述

請注意,函數和域是凸的(如果您熟悉這個概念,這意味著您可以假設該集合是“土豆狀的”並且函數是“碗狀的”)。

答案1

當然。這是一個例子。如果用編譯的話lualatex編譯速度會比較快。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={f(\x,\y)=1+\x*\x+\y*\y;}]
\matrix[column sep=3em]{
\begin{axis}[hide axis,domain=0:1,domain y=0:360,smooth,samples=25,samples y=61]
 \addplot3[surf,shader=flat] ({x*cos(y)},{0.8*x*sin(y)},{0}); 
 \addplot3[surf,shader=interp,z buffer=sort] ({x*cos(y)},{0.8*x*sin(y)},{f(x*cos(y),0.8*x*sin(y))});
\end{axis}
&
\begin{axis}[hide axis,domain=0:1,domain y=0:360,smooth,samples=25,samples y=61]
 \addplot3[surf,shader=flat] ({x*cos(y)*(2+sin(3*y))},{0.8*x*sin(y)*(2+sin(3*y)},{0}); 
 \addplot3[surf,shader=interp,z buffer=sort] ({x*cos(y)*(2+sin(3*y)},{0.8*x*sin(y)*(2+sin(3*y)},{f(x*cos(y),0.8*x*sin(y))});
\end{axis}\\
};
\end{tikzpicture}
\end{document}

在此輸入影像描述

或用三角形域。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={f(\x,\y)=1+\x*\x+\y*\y;}]
\matrix[column sep=3em]{
\begin{axis}[hide axis,domain=0:1,domain y=0:360,smooth,samples=25,samples y=61,
    declare function={myx(\x,\y)=\x*cos(\y);myy(\x,\y)=\x*sin(\y);}]
 \addplot3[surf,shader=flat] ({myx(x,y)},{myy(x,y)},{0}); 
 \addplot3[surf,shader=interp,z buffer=sort] 
    ({myx(x,y)},{myy(x,y)},{f(myx(x,y),myy(x,y))});
\end{axis}
&
\begin{axis}[hide axis,domain=-1:1,domain y=0:1,samples=25,samples y=61,
 declare function={myx(\x,\y)=\x;myy(\x,\y)=\y*(1-abs(\x));}]
 \addplot3[surf,shader=flat] ({myx(x,y)},{myy(x,y)},{0}); 
 \addplot3[surf,shader=interp,z buffer=sort] 
    ({myx(x,y)},{myy(x,y)},{f(myx(x,y),myy(x,y))});
\end{axis}\\
};
\end{tikzpicture}
\end{document}

在此輸入影像描述

請注意,您也可以使用濾鏡,但邊界通常看起來有點像素化。

相關內容