我有以下代码来构建楔形圆柱体:
\documentclass{article}
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xscale=1.2,yscale=1.2,
view={120}{15},
axis lines=center,xmax=2,ymax=2,xmin=-2,ymin=-1,zmin=-1,zmax=3,
width=12cm,height=10cm,enlargelimits=false,grid=major]
\node [left] at (axis cs:2.1,0,0) {eixo-$x$};
\node [right] at (axis cs:0,2.1,0) {eixo-$y$};
\node [above] at (axis cs:0,0,3.1) {eixo-$z$};
\addplot3+[domain=0:2*pi,name path=A, samples=200, samples y=0,no marks,black, opacity=0.9, fill opacity=0.9,samples=200, samples y = 0, no marks, black] ({cos(deg(x))},{sin(deg(x))},{0});
\addplot3+[domain=0:2*pi,name path=B, samples=200, samples y=0,no marks,black, opacity=0.9, fill opacity=0.9,samples=200, samples y = 0, no marks, black] ({cos(deg(x))},{sin(deg(x))},{2-sin(deg(x))});
\addplot [gray,opacity=0.3] fill between[of=A and B];
\end{axis}
\end{tikzpicture}
我绘制了下圆周(路径 A)、上椭圆(路径 B),我需要在这两条曲线之间填充以获得楔形边。但是当我使用时\fillbetween
,乳胶会填充顶部,我不想这样。我应该如何调整命令来做到这一点?
答案1
我认为您不能fillbetween
按照您建议的方式使用该库。一种方法是找到前端的参数化并绘制它。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xscale=1.2,yscale=1.2,
view={120}{15},
axis lines=center,xmax=2,ymax=2,xmin=-2,ymin=-1,zmin=-1,zmax=3,
width=12cm,height=10cm,enlargelimits=false,grid=major,
declare function={az=\pgfkeysvalueof{/pgfplots/view/az};}]
\node [left] at (axis cs:2.1,0,0) {eixo-$x$};
\node [right] at (axis cs:0,2.1,0) {eixo-$y$};
\node [above] at (axis cs:0,0,3.1) {eixo-$z$};
\addplot3+[domain=0:2*pi,name path=A, samples=200, samples y=0,no marks,black, opacity=0.9, fill opacity=0.9,samples=200, samples y = 0, no marks, black] ({cos(deg(x))},{sin(deg(x))},{0});
\addplot3+[domain=0:2*pi,name path=B, samples=200, samples y=0,no marks,black, opacity=0.9, fill opacity=0.9,samples=200, samples y = 0, no marks, black] ({cos(deg(x))},{sin(deg(x))},{2-sin(deg(x))});
\path[fill=gray,fill opacity=0.3] plot[variable=\t,domain=az:az-190]
({cos(\t)},{sin(\t)},{2-sin(\t)})
-- plot[variable=\t,domain=az-180:az]
({cos(\t)},{sin(\t)},{0}) -- cycle;
%\addplot [gray,opacity=0.3] fill between[of=A and B];
\end{axis}
\end{tikzpicture}
\end{document}
您可以稍微简化一下这一过程。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={120}{15}, width=12cm,height=10cm,
axis lines=center,
xmax=2,ymax=2,xmin=-2,ymin=-1,zmin=-1,zmax=3,
x label style={at={(axis cs:2.1,0,0)},anchor=east},
xlabel=eixo-$x$,
y label style={at={(axis cs:0,2.1,0)},anchor=west},
ylabel=eixo-$y$,
z label style={at={(axis cs:0,0,3.1)},anchor=south},
zlabel=eixo-$z$,
enlargelimits=false,grid=major,
declare function={az=\pgfkeysvalueof{/pgfplots/view/az};}]
\addplot3[domain=0:2*pi,samples=101,samples y = 0, no marks, black] ({cos(deg(x))},{sin(deg(x))},{0});
\addplot3[domain=0:2*pi,samples=101,samples y = 0, no marks, black] ({cos(deg(x))},{sin(deg(x))},{2-sin(deg(x))});
\path[fill=gray,fill opacity=0.3] plot[variable=\t,domain=az:az-190]
({cos(\t)},{sin(\t)},{2-sin(\t)})
-- plot[variable=\t,domain=az-180:az]
({cos(\t)},{sin(\t)},{0}) -- cycle;
\end{axis}
\end{tikzpicture}
\end{document}
当然,你也可以利用这个事实pgfplots
,用其真正的方法来增加覆盖力。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[view={120}{15}, width=12cm,height=10cm,
axis lines=center,set layers,
xmax=2,ymax=2,xmin=-2,ymin=-1,zmin=-1,zmax=3,
x label style={at={(axis cs:2.1,0,0)},anchor=east},
xlabel=eixo-$x$,
y label style={at={(axis cs:0,2.1,0)},anchor=west},
ylabel=eixo-$y$,
z label style={at={(axis cs:0,0,3.1)},anchor=south},
zlabel=eixo-$z$,
enlargelimits=false,grid=major,
declare function={az=\pgfkeysvalueof{/pgfplots/view/az};}]
\begin{pgfonlayer}{axis background}
\addplot3[domain=az:az+180,samples=101,domain y=0:1,samples y=2,surf,
z buffer=sort] ({cos(x)},{sin(x)},{y*(2-sin(x))});
\end{pgfonlayer}
\addplot3[domain=az:az-180,samples=101,domain y=0:1,samples y=2,surf,
z buffer=sort] ({cos(x)},{sin(x)},{y*(2-sin(x))});
\end{axis}
\end{tikzpicture}
\end{document}