我尝试在同一张图上绘制 x^2+y^2−z^2=1 和 x−2z=0,并成功绘制了它们;但是,结果看起来很糟糕,重叠性很差。我该如何修复重叠,使结果pgfplots
看起来更像 Apple Grapher 的结果?
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xlabel=$x$,
ylabel=$y$,
xmin=-3.5,
xmax=3.5,
ymax=3,
ymin=-2.5
]
\addplot3[mesh,domain=-3.5:3.5] {sqrt(x^2+y^2-1)};
\addplot3[mesh,domain=-3.5:3.5] {-sqrt(x^2+y^2-1)};
\addplot3[mesh,domain=-3.5:3.5] {x/2};
\end{axis}
\end{tikzpicture}
答案1
PGFPlots 在这方面会遇到真正的麻烦,但这里有一个使用 Asymptote 的解决方案:
请注意,这需要smoothcontour3
模块,该模块太新,在 TeXLive 2015 中不可用。如果你尝试运行它并且它抱怨模块缺失,请下载平滑轮廓3.asy并将该文件放在与您要编译的文件asy
相同的文件夹/目录中。tex
% file: foo.tex
% to compile: pdflatex --shell-escape foo
%
% For MikTeX users: Asymptote requires a separate program that cannot be installed
% by the package manager. You can get the installation file from
% https://sourceforge.net/projects/asymptote/files/2.35/
% (specifically, the file ending in setup.exe).
\documentclass{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=PlaneAndHyperboloid}
settings.outformat = "png";
settings.render = 8;
import graph3;
import smoothcontour3;
import palette;
size(15cm);
currentprojection = perspective(5*(-5,-5,1.5));
real f(real x, real y, real z) { return x^2 + y^2 - z^2 - 1; }
real g(pair xy) { return xy.x / 2; }
real xmin = -3.5, ymin = -2.5, zmin = -2.5;
real xmax = 3.5, ymax = 2.5, zmax = 2.5;
surface hyperboloid =
implicitsurface(f, (xmin,ymin,zmin), (xmax,ymax,zmax), overlapedges=true);
hyperboloid.colors(palette(hyperboloid.map(zpart),Rainbow()));
draw(hyperboloid, light=nolight);
surface plane = surface(g, (xmin, ymin), (xmax,ymax));
draw(plane, light=nolight, surfacepen=gray+opacity(0.5));
xaxis3(Label("$x$",align=X), arrow=Arrow3, ticks=InOutTicks(Step=1), above=true);
yaxis3(Label("$y$",align=Y), arrow=Arrow3, ticks=InOutTicks(Step=1), above=true);
zaxis3(Label("$z$",align=Z), arrow=Arrow3, ticks=InOutTicks(Step=1), above=true);
\end{asypicture}
\end{document}