使用 tikzpicture 环境在圆内的三维空间中绘制图形场

使用 tikzpicture 环境在圆内的三维空间中绘制图形场

让我展示一下我想要的:

原来的

这个字段与我想要的不符,但是想法是一样的。

虽然这是我得到的......(使用tikzpicture环境):

我这样做

梅威瑟:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tasks}
\usepackage{vmargin}

\usepackage{pgfplots}
\usetikzlibrary{arrows.meta, patterns}
\pgfplotsset{compat=1.8}
\pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
\pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
\usepackage{amsmath}

\usepackage{mathtools}
\usepackage{vmargin}

\setpapersize{A4}
\setmargins{2.2cm}
{0.5cm}
{16.5cm}
{23.42cm}
{30pt}
{1cm}
{0pt}
{2cm}
\pagestyle{fancy}
\fancyhf{}
\cfoot{\large \thepage}
\renewcommand{\headrulewidth}{0pt}

\begin{document}

\begin{center}
\begin{tikzpicture}[scale=1.5]
        \begin{axis}[
            legend pos=outer north east,
            axis lines = center,
            label style={font=\tiny},
            legend style={font=\tiny},
            xticklabel style = {font=\tiny},
            yticklabel style = {font=\tiny},
            zticklabel style = {font=\tiny},
            xlabel = $x$,
            xmin=-4,
            ymin=-4,
            zmin=-4,
            xmax=4,
            ymax=4,
            zmax=4,
            ylabel = $y$,
            zlabel = $z$,
            domain=-3:3,
            domain y=-3:3,
            restrict z to domain=-3:3,
            view={160}{20}
        ]
            % Field
            \addplot3[opacity=0.9,surf,mesh/ordering=y varies,shader=interp,samples=60] {y*x*x-y};
            \addlegendentry{$f(x,y)$}
            % This planes should be circles...
            \addplot3[samples=20] {2};
            \addplot3[samples=20] {-2};
            % Points:
            \addplot3[soldot,black] coordinates {(sqrt(3),1,2)} node[above left] {\tiny $(\sqrt 3,1,2)$};
            \addplot3[soldot,black] coordinates {(-sqrt(3),1,2)} node[above right] {\tiny $(-\sqrt 3,1,2)$};
            \addplot3[soldot,black] coordinates {(sqrt(3),-1,-2)} node[below left] {\tiny $(\sqrt 3,-1,-2)$};
            \addplot3[soldot,black] coordinates {(-sqrt(3),-1,-2)} node[below right] {\tiny $(-\sqrt 3,-1,-2)$};
    \end{axis}
\end{tikzpicture}
\end{center}

\end{document}

非常糟糕,不是吗?:'D

如果可能的话,我需要在您的帮助下使原始图像看起来尽可能好。该字段的样本是,60没有更多,因为在该值之后我收到错误:! TeX capacity exceeded, sorry [main memory size=3000000]。对不起,我的电脑不好:)

我想保留轴的限制,但在图中没有出现那些尖刺太可怕了...我指的是这些尖峰:

田野的尖刺

另外纠正视图会很棒(并尝试不添加opacity命令)。

有没有办法以最简单的方式实现这一点?

谢谢你!!

PS:场地在f(x, y) = y * x^2 - y圆圈内x^2 + y^2 <= 4

PS2:希望在里约感到焦虑的人们也能够给予合作:P

答案1

我稍微改变了函数的定义,使其仅存在于圆中x^2 + y^2 <= 4。我还改变了阴影,因为我认为这样形状会更清晰一些。容量问题可以通过分别更改xy(此图中的tr)的采样数来解决。非常感谢@marmot 提出使用极坐标的想法。

\addplot3[surf,mesh/ordering=y varies,shader=faceted,samples=72,samples y=20,variable=t,variable y=r,domain=0:360,domain y=0:2,line join=round] ({r*cos(t)},{r*sin(t)},{r*r*r*sin(t)*cos(t)*cos(t)-r*sin(t)});

我使用rt表示 ρ 和 θ 只是为了便于阅读。圆也可以用极坐标绘制,使用

\addplot3[samples=30,smooth,variable=t,domain=0:360] ({2*cos(t)},{2*sin(t)},2);

我还添加了axis on top冗余选项opacity=0.9,但这并没有提供适当的 3D 效果。我认为这应该是另一个问题。使用键可以更改视图view={}{},我发现view={110}{25}效果非常好。

完整代码:

\documentclass[tikz,margin=2mm]{standalone}
\usepackage{amssymb}

\usepackage{pgfplots}
\usetikzlibrary{arrows.meta, patterns}
\pgfplotsset{compat=1.8}
\pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
\pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
\usepackage{amsmath}

\usepackage{mathtools}

\begin{document}

\begin{tikzpicture}[scale=1.5]
        \begin{axis}[
            legend pos=outer north east,
            axis lines = center,
            label style={font=\tiny},
            legend style={font=\tiny},
            xticklabel style = {font=\tiny},
            yticklabel style = {font=\tiny},
            zticklabel style = {font=\tiny},
            xlabel = $x$,
            xmin=-4,
            ymin=-4,
            zmin=-4,
            xmax=4,
            ymax=4,
            zmax=4,
            ylabel = $y$,
            zlabel = $z$,
            domain=-3:3,
            domain y=-3:3,
            view={110}{25},
            axis on top,
        ]
            % Field
%            \addplot3[opacity=0.9,surf,mesh/ordering=y varies,shader=interp,samples=60] {y*x*x-y};
            \addplot3[surf,mesh/ordering=y varies,shader=faceted,samples=72,samples y=20,variable=t,variable y=r,domain=0:360,domain y=0:2,line join=round] ({r*cos(t)},{r*sin(t)},{r*r*r*sin(t)*cos(t)*cos(t)-r*sin(t)});
            \addlegendentry{$f(x,y)$}
            % This planes should be circles...
            \addplot3[samples=30,smooth,variable=t,domain=0:360] ({2*cos(t)},{2*sin(t)},2);
            \addplot3[samples=30,smooth,variable=t,domain=0:360] ({2*cos(t)},{2*sin(t)},-2);
            % Points:
            \addplot3[soldot,black] coordinates {(sqrt(3),1,2)} node[above left] {\tiny $(\sqrt 3,1,2)$};
            \addplot3[soldot,black] coordinates {(-sqrt(3),1,2)} node[above right] {\tiny $(-\sqrt 3,1,2)$};
            \addplot3[soldot,black] coordinates {(sqrt(3),-1,-2)} node[below left] {\tiny $(\sqrt 3,-1,-2)$};
            \addplot3[soldot,black] coordinates {(-sqrt(3),-1,-2)} node[below right] {\tiny $(-\sqrt 3,-1,-2)$};
    \end{axis}
\end{tikzpicture}

\end{document}

当然结果是:

在此处输入图片描述

免责声明:我没有解决点的位置及其标签放置问题,我将把这个问题留给你:)

编辑
根据要求,当从正 z 轴查看并且轴限值较小时,点标签会被剪裁。使用clip=false可防止出现这种情况。

代码:

\documentclass[tikz,margin=2mm]{standalone}
\usepackage{amssymb}

\usepackage{pgfplots}
\usetikzlibrary{arrows.meta, patterns}
\pgfplotsset{compat=1.8}
\pgfplotsset{soldot/.style={color=black,only marks,mark=*}}
\pgfplotsset{holdot/.style={color=red,fill=white,very thick,only marks,mark=*}}
\usepackage{amsmath}

\usepackage{mathtools}

\begin{document}

\begin{tikzpicture}[scale=1.5]
        \begin{axis}[
            legend pos=outer north east,
            axis lines = center,
            label style={font=\tiny},
            legend style={font=\tiny},
            xticklabel style = {font=\tiny},
            yticklabel style = {font=\tiny},
            zticklabel style = {font=\tiny},
            xlabel = $x$,
%            xmin=-4,
%            ymin=-4,
            xmin=-2.5,
            ymin=-2.5,
            zmin=-4,
%            xmax=4,
%            ymax=4,
            xmax=2.5,
            ymax=2.5,
            zmax=4,
            ylabel = $y$,
            zlabel = $z$,
            domain=-3:3,
            domain y=-3:3,
%            view={110}{25},
            view={0}{90},
            axis on top,
            clip=false,
        ]
            % Field
%            \addplot3[opacity=0.9,surf,mesh/ordering=y varies,shader=interp,samples=60] {y*x*x-y};
            \addplot3[surf,mesh/ordering=y varies,shader=faceted,samples=72,samples y=20,variable=t,variable y=r,domain=0:360,domain y=0:2,line join=round] ({r*cos(t)},{r*sin(t)},{r*r*r*sin(t)*cos(t)*cos(t)-r*sin(t)});
            \addlegendentry{$f(x,y)$}
            % This planes should be circles...
            \addplot3[samples=30,smooth,variable=t,domain=0:360] ({2*cos(t)},{2*sin(t)},2);
            \addplot3[samples=30,smooth,variable=t,domain=0:360] ({2*cos(t)},{2*sin(t)},-2);
            % Points:
            \addplot3[soldot,black] coordinates {(sqrt(3),1,2)} node[above right] {\tiny $(\sqrt 3,1,2)$};
            \addplot3[soldot,black] coordinates {(-sqrt(3),1,2)} node[above left] {\tiny $(-\sqrt 3,1,2)$};
            \addplot3[soldot,black] coordinates {(sqrt(3),-1,-2)} node[below right] {\tiny $(\sqrt 3,-1,-2)$};
            \addplot3[soldot,black] coordinates {(-sqrt(3),-1,-2)} node[below left] {\tiny $(-\sqrt 3,-1,-2)$};
    \end{axis}
\end{tikzpicture}

\end{document}

结果:

在此处输入图片描述

答案2

只是为了好玩,在渐近线中改编的一个选项

结果: 在此处输入图片描述

梅威瑟:

% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
% arara: asymptote
% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
\documentclass[border=20pt]{standalone}
\usepackage{asymptote}
\begin{document}
    \begin{asy}
        import three;
        import graph3;
        import grid3;   
        size(400,600);
        currentprojection=orthographic(5,1.5,1);
        //scale(Linear, Linear, Linear);
        limits((-5,-3,-3),(5,3,3));

        triple f(pair t) {
        return (2*t.y*cos(t.x),2*t.y*sin(t.x),2*t.y*sin(t.x)-8*t.y*sin(t.x)*cos(t.x)*cos(t.x));
        }
        triple g(pair t) {
        return (2*t.y*cos(t.x),2*t.y*sin(t.x),-2);
        }
        triple h(pair t) {
        return (2*t.y*cos(t.x),2*t.y*sin(t.x),2);
        }
        triple j(pair t) {
        return (3*t.x,3*t.y,0);
        }

        pen p=rgb(0,0,0)+thick();
        surface s=surface(f,(0,0),(2pi,1),120,5,Spline);
        surface t=surface(g,(0,0),(2pi,1),90,5,Spline);
        surface u=surface(h,(0,0),(2pi,1),90,5,Spline);
        surface v=surface(j,(-1,-1),(1,1),1,1,Spline);

        //surface only
        //draw(s,lightgray);

        // mesh only
         draw(v,surfacepen=material(white+opacity(0.8),
         ambientpen=gray),meshpen=p);
         draw(s,surfacepen=material(purple+opacity(0.5),
         ambientpen=purple),meshpen=p);
         draw(t,surfacepen=material(white+opacity(0.5),
         ambientpen=white),meshpen=p);
         draw(u,surfacepen=material(white+opacity(0.5),
         ambientpen=white),meshpen=p);
         path3 i=(sqrt(3),-1,2)..(sqrt(3),1,-2)..(0,2,2)..(-sqrt(3),1,-2)..(-sqrt(3),-1,2)..(0,-2,-2)..cycle;
         dot(i,8bp+.8blue);
         label("D",(sqrt(3),-1,2),N);
         label("A",(sqrt(3),1,-2),N);
         label("C",(0,2,2),N);
         label("E",(-sqrt(3),1,-2),N);
         label("B",(-sqrt(3),-1,2),N);
         label("F",(0,-2,-2),N);
         xaxis3(Label("$x$",1),red,arrow=Arrow3,OutTicks(Step=1));
         yaxis3(Label("$y$",1),green,arrow=Arrow3,OutTicks(Step=1));
         zaxis3(Label("$z$",1),blue,arrow=Arrow3,OutTicks(Step=1));

        // surface & mesh
        //draw(s,lightgray,meshpen=p,render(merge=true));

    \end{asy}
\end{document}

相关内容