使用 LaTex 绘制 3D 曲面

使用 LaTex 绘制 3D 曲面

我很喜欢学习使用 LaTex 绘制二维曲线。现在我想学习绘制三维曲面。在下图中,我想我可以绘制坐标轴和区域 R。但我想知道是否也可以使用 LaTex 绘制图像中的曲面。

在此处输入图片描述

答案1

可以使用 生成 3D 图\addplot3

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[unit vector ratio=1 1 1,
    width=16cm,
    hide axis,
    view={-45}{5},
    colormap/violet,
    declare function={f(\y)=(\y<180?1:1+0.2*sin(\y));}]
 \addplot3[surf,shader=interp,domain=0:1,domain y=0:360,z buffer=sort]
    ({x*cos(y)*f(y)},
     {x*sin(y)*f(y)},
     {pow(x*f(y),2)});
 \addplot3[surf,shader=interp,domain=0:1,domain y=0:360,z buffer=sort]
    ({x*cos(y)*f(y)},
     {x*sin(y)*f(y)},
     {2-pow(x*f(y),2)});
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

另一个选择,仅使用 tikz:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[scale=3,line cap=round,line join=round,x={(-0.30cm,-0.53cm)},y={(0.95cm,-0.17cm)},z={(0cm,0.83cm)}]
\draw[red,fill=green!30] (0,0,0) -- (1,0,0) -- (0,1,0) -- cycle;
\draw[-latex] (0,0,0) -- (2,0,0) node[left]  {$x$};
\draw[-latex] (0,0,0) -- (0,2,0) node[right] {$y$};
\draw[-latex] (0,0,0) -- (0,0,3) node[above] {$z$};
\foreach\a in{0,10,...,90}
{%
  \pgfmathsetmacro\e{1/(sin(\a)+cos(\a))}
  \draw[orange] plot[domain=0:\e,samples=50,smooth] ({\x*sin(\a)},{\x*cos(\a)},2-\x*\x);
  \draw[orange] plot[domain=0:\e,samples=50,smooth] ({\x*sin(\a)},{\x*cos(\a)},  \x*\x);
}
\foreach\b in{0.1,0.2,...,1}
{%
  \draw[orange] plot[domain=0:\b,samples=50,smooth] (\x,\b-\x,{2-\x*\x-(\b-\x)*(\b-\x)});
  \draw[orange] plot[domain=0:\b,samples=50,smooth] (\x,\b-\x,  {\x*\x+(\b-\x)*(\b-\x)});
}
\node at (0,0.7,1.5) [right] {$z=2-x^2-y^2$};
\node at (0,0.7,0.5) [right] {$z=x^2+y^2$};
\node at (0.3,0.3)           {$R$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

\documentclass[12pt]{article}



\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{tikz, tkz-euclide,tikz-3dplot,ifthen}
\usetikzlibrary{arrows,decorations.markings,calc,fadings,decorations.pathreplacing, patterns, decorations.pathmorphing, positioning}
\usepgfplotslibrary{fillbetween}

\begin{document}



\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
 view={120}{30},
 ticks=none,
  zmin=-0.5,zmax=3,
  xmin=-3,xmax=3,
  ymin=-3,ymax=3,]

\addplot3 [name path = curve1,domain=0:1, y domain = 0:0,]
          (x,0,{2-x^2});
\addplot3 [name path = curve2,domain=0:1, y domain = 0:0,]
          (0,x,{2-x^2});
\addplot3 [name path = curve3,domain=0.5:1, y domain = 0:0,]
          (x,1-x,{2-x^2-(1-x)^2});
\addplot3 [name path = curve4,domain=0:0.5, y domain = 0:0,]
          (x,1-x,{2-x^2-(1-x)^2});

\addplot3 [name path = curve5,domain=0.7:1, y domain = 0:0,]
          (x,1-x,{x^2+(1-x)^2});
\addplot3 [name path = curve6,domain=0.3:0.7, y domain = 0:0,]
          (x,1-x,{x^2+(1-x)^2});
\addplot3 [name path = curve7,domain=0:0.3, y domain = 0:0,]
          (x,1-x,{x^2+(1-x)^2});
\addplot3 [name path = curve8,domain=0.3:1, y domain = 0:0,]
          (x,0,{x^2});
\addplot3 [name path = curve9,domain=0.3:1, y domain = 0:0,]
          (0,x,{x^2});
\addplot3 [name path = curve10,domain=0:0.3, y domain = 0:0,]
          (x,0.3-x,{x^2+(0.3-x)^2});

         \addplot [ color = gray!50,opacity=0.5, draw = none]
      fill between[of = curve1 and curve3];
               \addplot [ color = gray!50,opacity=0.5, draw = none]
      fill between[of = curve2 and curve4];

                     \addplot [ color = gray!50,opacity=0.5, draw = none]
      fill between[of = curve5 and curve8];
                    \addplot [ color = gray!50,opacity=0.5, draw = none]
      fill between[of = curve6 and curve10];
      
                 \addplot [ color = gray!50,opacity=0.5, draw = none]
      fill between[of = curve7 and curve9];



  
\end{axis}
\end{tikzpicture}



\end{document}

在此处输入图片描述

相关内容