我尝试用参数符号(即 ({x},{y},{sort(x^2-y^2)})绘制图形,如下面的代码所示,但没有什么能够呈现图形计算器上显示的图像。
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
grid=major,
3d box=complete,
enlargelimits=false,
colormap/cool,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
zlabel style = {sloped like x axis}
]
\addplot3 [
surf,
shader=faceted,
samples=50,
z buffer=sort,
] {sqrt((x)^2-(y)^2)};
\end{axis}
\end{tikzpicture}
答案1
你几乎做对了所有事情,pgfplots
只是不太擅长取负数的平方根。所以如果你稍微调整一下域,你就会得到
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
grid=major,
3d box=complete,
enlargelimits=false,
colormap/cool,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
zlabel style = {sloped like x axis}
]
\addplot3 [domain=2:4,domain y=-2:2,
surf,
shader=faceted,
samples=50,
z buffer=sort,
] {sqrt(x^2-y^2)};
\end{axis}
\end{tikzpicture}
\end{document}
至于你在评论中的要求,可以将函数写为sqrt(u*v)
,其中u=x+y
和v=x-y
。然后x=(u+v)/2
和y=(u-v)/2
。由于变量只是参数图中的占位符,我们可以分别将u
和重命名v
为x
和y
,并得出
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[xmax=2,xmin=-2,
grid=major,
3d box=complete,
enlargelimits=false,
colormap/cool,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
zlabel style = {sloped like x axis}
]
\addplot3 [domain=0:4,domain y=0:4,
surf,
shader=faceted,
samples=50,
z buffer=sort,
] ({(x+y)/2},{(x-y)/2},{sqrt(x*y)});
\addplot3 [domain=0:4,domain y=0:4,
surf,
shader=faceted,
samples=50,
z buffer=sort,
] ({-(x+y)/2},{-(x-y)/2},{sqrt(x*y)});
\end{axis}
\end{tikzpicture}
\end{document}