如何:Tikz 对象的 3d 图

如何:Tikz 对象的 3d 图

嗨,我在绘制积分区域时遇到了问题。在x-y-平面中,该区域由多项式 3x^2-1 和 3-x^2 界定。在z-方向上有极限z=0z=4-x-y。现在我想在 3d 中绘制对象。

我的想法:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usepackage[ngerman]{babel}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    grid,
    grid style={dashed,gray!30},
    smooth,
    xmin=-3, xmax=3,
    ymin=-2, ymax=4,
    %axis lines=middle,
    xlabel=$x$,
    xlabel style={below, anchor=north east,inner xsep=0pt},
    xtick={-2,...,2},
    ylabel=$y$,
    ylabel style={above,anchor=south,inner ysep=0pt},
    ytick={-2,...,3},
    zlabel=$z$,
    ztick={0,5,10},
]
\addplot3[name path=z,mesh,samples=20,domain=-4:4]{4-x-y};
\addlegendentry{$z=4-x-y$}

\addplot[red,name path=f1,mark=none,domain=-2:2,line legend] {3-x^2};
\addlegendentry{$f_{1}(x)$}

\addplot[blue,name path=f2,mark=none,domain=-1.25:1.25, line legend] {3*x^2-1};
\addlegendentry{$f_{2}(x)$}

\path[name path=lower,intersection segments={of=f1 and f2,sequence=B0 -- A1}];
\addplot[pattern=north west lines, pattern color=green]fill between[of=f2 and lower];
\addlegendentry{$\cal{A}$}

\end{axis}
\end{tikzpicture}
\end{document}

1

答案1

基本上,我通过将其分成两部分(y = 3-x^2 和 y = 3x^2-1)并对其进行参数化来绘制您感兴趣的区域的边界。

找到合适的颜色让所有东西都清晰可见似乎是另一个问题。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    grid,
    grid style={dashed,gray!30},
    smooth,
    xmin=-3, xmax=3,
    ymin=-2, ymax=4,
    %axis lines=middle,
    xlabel=$x$,
    xlabel style={below, anchor=north east,inner xsep=0pt},
    xtick={-2,...,2},
    ylabel=$y$,
    ylabel style={above,anchor=south,inner ysep=0pt},
    ytick={-2,...,3},
    zlabel=$z$,
    ztick={0,5,10},
]


\addplot[red,name path=f1,mark=none,domain=-2:2,line legend] {3-x^2};
\addlegendentry{$f_{1}(x)$}

\addplot[blue,name path=f2,mark=none,domain=-1.25:1.25, line legend] {3*x^2-1};
\addlegendentry{$f_{2}(x)$}

\addplot3[surf,opacity=0.2,color=red,faceted color=red,domain=-1:1,y domain=0:1]({x},{3*x^2-1},{y*(5-x-3*x^2)});
\addplot3[surf,color=red,faceted color=red,opacity=0.2,domain=-1:1,y domain=0:1]({x},{3-x^2},{y*(x^2+1-x)});

\addplot3[surf,name path=z,faceted color=blue,color=blue,samples=20,domain=-3:3,opacity=0.1]{4-x-y};


\path[name path=lower,intersection segments={of=f1 and f2,sequence=B0 -- A1}];
\addplot[pattern=north west lines, pattern color=green]fill between[of=f2 and lower];


\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容