如何使用 PGFPlots 填充由 x^2+y^2

如何使用 PGFPlots 填充由 x^2+y^2

我想绘制Dx^2+y^2<=9z<=16-x^2-y^2和定义的身体z>=0

我们必须绘制图形x^2+y^2=9z=16-x^2-y^2并且降低不透明度,然后填充(或使用图案)交叉点以创建由前面的表达式定义的z=0主体:D

我想要的是

但是,我无法完成任务。以下是 MWE:

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis} [
                axis on top,
                axis lines=center,
                xlabel=$x$,
                ylabel=$y$,
                zlabel=$z$,
                xmin=-5,
                ymin=-5,
                zmin=-1,
                xmax=5,
                ymax=5,
                zmax=17,
                xtick={-4,-3,0,3,4},
                xticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ytick={-4,-3,0,3,4},
                yticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ztick={0,16},
                zticklabels={$0$,$16$},
                ticklabel style={font=\tiny},
                legend pos=outer north east,
                legend style={at={(1.25,.81)},anchor=north east},
                legend cell align={left},
                view={135}{25}
            ]
            \addplot3[orange,opacity=.5,samples=51,samples y=21,variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({r*cos(t)},{r*sin(t)},{16-r*r});   % z=16-x^2-y^2
            \addlegendentry{\(16-x^2-y^2\)}
            \addplot3[green,opacity=.5,samples=51,samples y=21,variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({3*cos(t)},{3*sin(t)},{0});   % x^2+y^2=9
            \addlegendentry{\(x^2+y^2=9\)}
            \fill[cyan,opacity=.5] (3,3,0) -- (3,-3,0) -- (-3,-3,0) 
        -- (-3,3,0);    % z=0
            \addlegendentry{\(z=0\)}    % This label is not showing because we used 'fill', not 'addplot3'
            % Here should be the code of the intersection of the three surfaces...
        \end{axis}
    \end{tikzpicture}
\end{center}

\end{document}

我做了什么

编辑。非常感谢土拨鼠谁帮助我部分完成了我想要的:

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis} [
                axis on top,
                axis lines=center,
                xlabel=$x$,
                ylabel=$y$,
                zlabel=$z$,
                xmin=-5,
                ymin=-5,
                zmin=-1,
                xmax=5,
                ymax=5,
                zmax=17,
                xtick={-4,-3,0,3,4},
                xticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ytick={-4,-3,0,3,4},
                yticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ztick={0,16},
                zticklabels={$0$,$16$},
                ticklabel style={font=\tiny},
                legend pos=outer north east,
                legend style={at={(1.45,.85)},anchor=north east},
                legend cell align={left},
                view={135}{25}
            ]
            \addplot3[opacity=.5,surf,shader=interp,colormap={orange}{color=(orange!50) color=(orange!50)},variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({r*cos(t)},{r*sin(t)},{16-r*r});  % z=16-x^2-y^2
            \addlegendentry{\(z=16-x^2-y^2\)}
            \addplot3[opacity=.5,surf,shader=interp,domain=0:360,domain y=0:16,colormap={green}{color=(green!50) color=(green!50)}] ({3*cos(x)},{3*sin(x)},{y}); % x^2+y^2=9
            \addlegendentry{\(x^2+y^2=9\)}
            %\fill[cyan,opacity=.5] (4,4,0) -- (4,-4,0) -- (-4,-4,0) -- (-4,4,0);    % z=0
            \addplot3[fill=cyan,opacity=.5,domain=-4:4, domain y=-4:4] (x,y,0);
            \addlegendentry{\(z=0\)}
        \end{axis}
    \end{tikzpicture}
\end{center}

\end{document}

新MWE

然而,我们需要:

  • 修复输出z=0(我不想使用,fill因为这不是情节,所以我们无法添加图例)。
  • 填充实体D使用模式:固体使用模式或填写:固体填充什么需要更少的编程时间。

一些感兴趣的链接:

谢谢!!

答案1

怎么样

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis} [
                axis on top,
                axis lines=center,
                xlabel=$x$,
                ylabel=$y$,
                zlabel=$z$,
                xmin=-5,
                ymin=-5,
                zmin=-1,
                xmax=5,
                ymax=5,
                zmax=17,
                xtick={-4,-3,0,3,4},
                xticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ytick={-4,-3,0,3,4},
                yticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ztick={0,16},
                zticklabels={$0$,$16$},
                ticklabel style={font=\tiny},
                legend pos=outer north east,
                legend style={at={(1.45,.85)},anchor=north east},
                legend cell align={left},
                view={135}{25}
            ]
            \addplot3[opacity=.5,surf,shader=interp,colormap={orange}{color=(orange!50) color=(orange!50)},variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({r*cos(t)},{r*sin(t)},{16-r*r});  % z=16-x^2-y^2
            \addlegendentry{\(z=16-x^2-y^2\)}
            \addplot3[opacity=.5,surf,shader=interp,domain=0:360,domain y=0:16,colormap={green}{color=(green!50) color=(green!50)}] ({3*cos(x)},{3*sin(x)},{y}); % x^2+y^2=9
            \addlegendentry{\(x^2+y^2=9\)}
            %\fill[cyan,opacity=.5] (4,4,0) -- (4,-4,0) -- (-4,-4,0) -- (-4,4,0);    % z=0
            \addplot3[surf,shader=interp,opacity=.5,domain=-4:4, domain y=-4:4,
            colormap={dull}{color=(cyan) color=(cyan)},opacity=0.5] {0};
            \addlegendentry{\(z=0\)}
            \addplot3[mesh,color=gray,ultra thin,domain=0:360,domain y=0:4,z
            buffer=sort,samples=31,samples y=41] 
            ({min(y,3)*cos(x)},{min(y,3)*sin(x)},{16-y*y});
        \end{axis}
    \end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

? 它可能成为关押讨厌的鸭子的漂亮笼子。;-)

这显示了表面。我不知道你想用原始图做什么。

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis} [
                axis on top,
                axis lines=center,
                xlabel=$x$,
                ylabel=$y$,
                zlabel=$z$,
                xmin=-5,
                ymin=-5,
                zmin=-1,
                xmax=5,
                ymax=5,
                zmax=17,
                xtick={-4,-3,0,3,4},
                xticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ytick={-4,-3,0,3,4},
                yticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ztick={0,16},
                zticklabels={$0$,$16$},
                ticklabel style={font=\tiny},
                legend pos=outer north east,
                legend style={at={(1.25,.81)},anchor=north east},
                legend cell align={left},
                view={135}{25}
            ]
%             \addplot3[orange,opacity=.5,samples=51,samples y=21,variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({r*cos(t)},{r*sin(t)},{16-r*r});   % z=16-x^2-y^2
%             \addlegendentry{\(16-x^2-y^2\)}
%             \addplot3[green,opacity=.5,samples=51,samples y=21,variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({3*cos(t)},{3*sin(t)},{0});   % x^2+y^2=9
%             \addlegendentry{\(x^2+y^2=9\)}
%             \fill[cyan,opacity=.5] (3,3,0) -- (3,-3,0) -- (-3,-3,0) 
%         -- (-3,3,0);    % z=0
%             %\addlegendentry{\(z=0\)}    % This label is not showing because we used 'fill', not 'addplot3'
            % Here should be the code of the intersection of the three surfaces...
            \addplot3[surf,shader=interp,domain=0:360,domain y=0:7,z buffer=sort] 
            ({3*cos(x)},{3*sin(x)},{y});
            \addplot3[data cs=polar,surf,shader=interp,domain=0:360,domain y=0:3] {16-y*y};
        \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

在我看来,这就像一个有毒的蘑菇:

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis} [
                axis on top,
                axis lines=center,
                xlabel=$x$,
                ylabel=$y$,
                zlabel=$z$,
                xmin=-5,
                ymin=-5,
                zmin=-1,
                xmax=5,
                ymax=5,
                zmax=17,
                xtick={-4,-3,0,3,4},
                xticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ytick={-4,-3,0,3,4},
                yticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ztick={0,16},
                zticklabels={$0$,$16$},
                ticklabel style={font=\tiny},
                legend pos=outer north east,
                legend style={at={(1.25,.81)},anchor=north east},
                legend cell align={left},
                view={135}{25}
            ]
%             \addplot3[orange,opacity=.5,samples=51,samples y=21,variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({r*cos(t)},{r*sin(t)},{16-r*r});   % z=16-x^2-y^2
%             \addlegendentry{\(16-x^2-y^2\)}
%             \addplot3[green,opacity=.5,samples=51,samples y=21,variable=t,variable y=r,domain=0:360,domain y=0:2*pi,restrict z to domain=0:16] ({3*cos(t)},{3*sin(t)},{0});   % x^2+y^2=9
%             \addlegendentry{\(x^2+y^2=9\)}
%             \fill[cyan,opacity=.5] (3,3,0) -- (3,-3,0) -- (-3,-3,0) 
%         -- (-3,3,0);    % z=0
%             %\addlegendentry{\(z=0\)}    % This label is not showing because we used 'fill', not 'addplot3'
            % Here should be the code of the intersection of the three surfaces...
            \addplot3[surf,shader=interp,domain=0:360,domain y=0:7,z
            buffer=sort,colormap=
        {greenblack}{color=(green!50!black) color=(green)}] 
            ({3*cos(x)},{3*sin(x)},{y});
            \addplot3[data cs=polar,surf,shader=interp,domain=0:360,domain y=0:3,color=orange] {16-y*y};
        \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

也可以一次性绘制出来。

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis} [
                axis on top,
                axis lines=center,
                xlabel=$x$,
                ylabel=$y$,
                zlabel=$z$,
                xmin=-5,
                ymin=-5,
                zmin=-1,
                xmax=5,
                ymax=5,
                zmax=17,
                xtick={-4,-3,0,3,4},
                xticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ytick={-4,-3,0,3,4},
                yticklabels={$-4$,$-3$,$0$,$3$,$4$},
                ztick={0,16},
                zticklabels={$0$,$16$},
                ticklabel style={font=\tiny},
                legend pos=outer north east,
                legend style={at={(1.25,.81)},anchor=north east},
                legend cell align={left},
                view={135}{25}
            ]
            % Here should be the code of the intersection of the three surfaces...
            \addplot3[surf,shader=interp,domain=0:360,domain y=0:4,z
            buffer=sort,colormap=
        {greenorange}{color=(green!80!black) color=(orange)},samples=31,samples
        y=41] 
            ({min(y,3)*cos(x)},{min(y,3)*sin(x)},{16-y*y});
        \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

相关内容