我正在尝试制作 3D 抛物柱面,但没有正确的技术。请帮忙
\begin{figure}[h]
\begin{center}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=1,tdplot_main_coords]
\draw[thick,black,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$};
\draw[thick,black,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$};
\draw[thick,black,->] (0,0,0) -- (0,0,4.5) node[anchor=south]{$z$};
\draw [blue,thick,dashed, domain=-2:2, samples=100] plot (\x,-2,\x*\x);
\draw [blue,thick,dashed, domain=-2:2, samples=100] plot (\x,-1,\x*\x);
\draw [blue,thick,dashed, domain=-2:2, samples=100] plot (\x,1,\x*\x);
\draw [blue,thick,dashed, domain=-2:2, samples=100] plot (\x,2,\x*\x);
%\draw [fill=blue!40, domain=-2:2, samples=100,opacity=.2] plot (\x,-2,\x*\x)--(2,2,4)--(-2,2,4)--(-2,-2,4);
%\draw [blue,thick,fill=blue!40, domain=2:-2, samples=100,opacity=.2] plot (\x,2,\x*\x)--(2,-2,4);
%\draw [fill=blue!40, domain=-2:2, samples=100,opacity=.2] plot (\x,2,\x*\x);
\end{tikzpicture}
\end{center}
\caption{}
\end{figure}
答案1
您可以使用类似 的内容进行填充plot ... -- plot ....
。
为了避免重复,我定义了两种样式。样式to parabola
是必需的,因为 tikz 无法解析类似的东西-- [...]
,但可以解析-- plot ...
。
\documentclass[tikz,border=7pt]{standalone}
\tikzset{
parabola/.style args={#1:#2:#3}{
insert path={plot[domain=#1:#2] (\x,#3,\x*\x)}
},
to parabola/.style args={#1:#2:#3}{
insert path={ -- plot[domain=#1:#2] (\x,#3,\x*\x)}
},
}
\begin{document}
\begin{tikzpicture}
% axes
\draw[thick,black,->] (0,0,0) to (3,0,0) node[below left]{$x$};
\draw[thick,black,->] (0,0,0) to (0,3,0) node[below right]{$y$};
\draw[thick,black,->] (0,0,0) to (0,0,4.5) node[below]{$z$};
% plot some parabolas
\foreach \y in {-2,-1,...,2}
\draw[blue,thick,dashed,samples=100,parabola={-2:3:\y}];
% fill between the first and the last parabola
\def\t{1.3}% found by trial and error
\fill[blue, fill opacity=.1] [parabola={-2:\t:-2}] [to parabola={\t:-2:2}];
\fill[blue, fill opacity=.1] [parabola={\t:3:-2}] [to parabola={3:\t:2}];
\end{tikzpicture}
\end{document}
注意:我将域名从 更改[-2:2]
为[-2:3]
。
答案2
\documentclass{article}
\usepackage{tikz,tikz-3dplot}
\begin{document}
\tikzset{
parabola/.style args={#1:#2:#3}{
insert path={plot[domain=#1:#2] (\x,#3,\x*\x)}
},
to parabola/.style args={#1:#2:#3}{
insert path={ -- plot[domain=#1:#2] (\x,#3,\x*\x)}
},
}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=1,tdplot_main_coords]
\draw[thick,black,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$};
\draw[thick,black,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$};
\draw[thick,black,->] (0,0,0) -- (0,0,5) node[anchor=south]{$z$};
\foreach \y in {-2,-1,...,2}
\draw[blue,thick,dashed,samples=100,parabola={-2:2:\y}];
% fill between the first and the last parabola
\def\t{0}% found by trial and error
\fill[blue, fill opacity=.1] [parabola={-2:\t:-2}] [to parabola={\t:-2:2}];
\fill[blue, fill opacity=.1] [parabola={\t:2:-2}] [to parabola={2:\t:2}];
\draw (-.5,-2.55,.25)--(-.5,1.45,.25);
\draw (-1,-2.85,1)--(-1,1.15,1);
\draw (-1.5,-3.2,2.25)--(-1.5,.8,2.25);
\end{tikzpicture}
\end{document}