我想要这个函数的图形:
这里从 geogebra 上看是这样的:
我想用 来绘制它tikz
,所以我写了这段代码:
\documentclass[a4paper, 12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={f(\x,\y)=(-\y*\y+2*\y*\x)/2-sin(deg(\y-\x));
g(\x,\y)=(\x*\x)/2+\y-\x;
}]
\begin{axis}[
zmax=7,
zmin=-7,
xmax=7,
xmin=0,
ymax=7,
ymin=-7,
view = {40}{50},
xlabel = $x$,
ylabel = $t$,
zlabel = {$z$}
]
\begin{scope}
\clip plot[variable=\x,domain=0:7] (\x,\x,{f(\x,\x)})
-- (0,0,{f(0,0)}) -- (7,7,{f(7,7)}) -- (7,-7,{f(7,-7)}) -- (0,-7,{f(0,-7)});
\addplot3[
surf,
samples=30,
domain=0:7,
y domain=-7:7,
fill opacity=1
] {f(x,y)};
\end{scope}
\begin{scope}
\clip plot[variable=\x,domain=0:7] (\x,\x,{g(\x,\x)})
-- (0,0,{g(0,0)}) -- (7,7,{g(7,7)}) -- (0,7,{g(0,7)});
\addplot3[
surf,
samples=30,
domain=0:7,
y domain=0:7,
fill opacity=1
] {g(x,y)};
\end{scope}
\addplot3[ultra thick,
y domain=0:0,
black, samples=500,
domain=0:7
]
({x},{x},{x*x/2});
\end{axis}
\end{tikzpicture}
\end{document}
问题是我得到了类似这样的信息:
它比 geogebra 的丑陋得多。
我认为存在的问题有:
- 缩放比例。z 轴的单位与 x 轴的单位不同。
- 视点。我不知道如何才能从“负面”角度看到图表,就像 geogebra 的图片一样。
我能做些什么?
提前致谢!
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
declare function={
f(\x,\y)=(-\y*\y+2*\y*\x)/2-sin(deg(\y-\x));
g(\x,\y)=(\x*\x)/2+\y-\x;
}]
\begin{axis}[
view={-60}{20},
xmin=-5, xmax=5.5,
ymin=-3, ymax=6,
zmin=-2, zmax=4,
xlabel=$x$, ylabel=$y$, zlabel=$z$,
axis lines=center,
xtick distance=2, ytick distance=2, ztick distance=2,
restrict z to domain=-8:8,
label style={font=\tiny}, ticklabel style={font=\tiny},
xticklabel style={inner sep=0pt}, yticklabel style={inner sep=0pt},
]
\begin{scope}
\clip plot[variable=\x, domain=0:3.5] (\x,\x,{f(\x,\x)}) -- (5,0,4) -- (5,-3,-8) -- (0,0,-8) -- cycle;
\addplot3[
surf,
shader=faceted interp, colormap/cool, point meta min=-3, point meta max=5,
samples=30,
domain=0:5,
y domain=-3:6,
opacity=0.7,
] {f(x,y)};
\end{scope}
\begin{scope}
\clip plot[variable=\x, domain=0:3.5] (\x,\x,{g(\x,\x)}) -- (0,6,4) -- (0,6,-2) -- cycle;
\addplot3[
surf,
shader=faceted interp, colormap/hot, point meta min=-3, point meta max=5,
samples=30,
domain=0:5,
y domain=-3:6,
opacity=0.7,
] {g(x,y)};
\end{scope}
\addplot3[
very thick, yellow,
samples=50, smooth,
samples y=1,
domain=0:5,
] ( x , x , {x*x/2} );
\draw (pi,0,0) -- (5.5,0,0);
\draw (0,-3,0) -- (0,0,0);
\draw (0,0,0) -- (0,0,4);
\end{axis}
\end{tikzpicture}
\end{document}