為了闡明我的問題,令 f 為函數 f(x,y)=x^2+y^2。現在我只想畫函數 f: X -> R 其中 X={(x,y) | 2*x^2+y^2<1} 但我想限制域,以便只繪製函數的內部部分。這是我的程式碼:
\begin{tikzpicture}[]
\begin{axis}[axis lines=center,
axis on top,
xtick=\empty,
ytick=\empty,
ztick=\empty,
xrange=-2:2,
yrange=-2:2
]
% function
\addplot3[domain=-2:2,y domain=-2:2,colormap/viridis,surf,opacity=0.5]
%shader=interp für optional Linien weg
{x^2+y^2};
% Line on the function
\addplot3[color=black,
samples=40,
domain=0:2*pi,
line width=1.0pt]
({2*cos(deg(x))},
{sin(deg(x))},
{(2*cos(deg(x)))^2+sin(deg(x))^2});
% Line on bottom
\addplot3[dashed,
samples=40,
domain=0:2*pi]
({2*cos(deg(x))},
{sin(deg(x))},
{0});
\end{axis}
\end{tikzpicture}
生成的圖像是:
現在我該如何做到只繪製黑線內部的「內部」部分。 (抱歉英文不好,我是德國人)
答案1
歡迎!我只想使用極座標。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[]
\begin{axis}[axis lines=center,
axis on top,
xtick=\empty,
ytick=\empty,
ztick=\empty,
xrange=-2:2,
yrange=-2:2
]
\begin{scope}
\addplot3[domain=0:1,y domain=0:2*pi,colormap/viridis,surf,opacity=0.5,
samples=5,samples y=40,
] %-0.2 just to avoid gaps
%shader=interp für optional Linien weg
({2*x*cos(deg(y))},{x*sin(deg(y))},{(2*x*cos(deg(y)))^2+(x*sin(deg(y)))^2});
\end{scope}
% Line on the function
\addplot3[color=black,
samples=40,
domain=0:2*pi,
line width=1.0pt]
({2*cos(deg(x))},
{sin(deg(x))},
{(2*cos(deg(x)))^2+(sin(deg(x)))^2});
% Line on bottom
\addplot3[dashed,
samples=40,
domain=0:2*pi,smooth]
({2*cos(deg(x))},
{sin(deg(x))},
{0});
\end{axis}
\end{tikzpicture}
\end{document}
你能堅持使用笛卡爾座標/pgfplots/restrict expr to domain
(例如restrict expr to domain={x^2/4+y^2}{0:1}
您的情況)。順便說一句,你的輪廓不包含{(x,y) | 2*x^2+y^2<1}
.它包含{(x,y) | x^2/4+y^2<1}
.然而,根據我的經驗,這不會為此類圖帶來非常好的結果,因為邊界會「像素化」。