如何在 TikZ 中绘制抛物面?

如何在 TikZ 中绘制抛物面?

我正在尝试使用以下代码绘制抛物面:

\documentclass[border=5mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[scale=1,yscale=.5]

\draw (0,0) arc (180:0:2);
\draw ({2-sqrt(3)},1) arc (180:0:{sqrt(3)});
\draw ({2-sqrt(2)},2) arc (180:0:{sqrt(2)});
\draw (1,3) arc (180:0:1);

\draw (0,0) arc (-180:0:2);
\draw ({2-sqrt(3)},1) arc (-180:0:{sqrt(3)});
\draw ({2-sqrt(2)},2) arc (-180:0:{sqrt(2)});
\draw (1,3) arc (-180:0:1);

\draw (0,0) parabola bend (2,4) (4,0);
\draw ({2-sqrt(2)},{-sqrt(2)}) parabola bend (2,4) ({2+sqrt(2)},{sqrt(2)});

\draw ({2-sqrt(2)},{-sqrt(2)}) node [below] {0};
\draw [->]({2-sqrt(2)},{-sqrt(2)}) --++ (5,5);
\draw ({2-sqrt(2)},{-sqrt(2)}) --++ (-2,-2);
\draw [->]({2-sqrt(2)},{-sqrt(2)}) --++ (-3,3);
\draw ({2-sqrt(2)},{-sqrt(2)}) --++ (3,-3);

\end{tikzpicture}

\end{document}

结果如下:

在此处输入图片描述

但是,我不知道如何绘制抛物面的轮廓。我还需要为每个水平带着色。

或者,有没有更好的方法来做到这一点?

答案1

这不是一个优雅的解决方案,但最终还是成功了:

\documentclass[border=3mm]{standalone}

\usepackage{tikz,amsmath}
\usetikzlibrary{calc,shapes.geometric}

\begin{document}

\begin{tikzpicture}[scale=1,yscale=.5]

\fill [even odd rule, blue, opacity=0.3] ({-sqrt(2)},{-sqrt(2)-2}) rectangle ({6-sqrt(2)},{-sqrt(2)+6.5}) ({2-sqrt(4-1/4)},{1/2}) parabola bend (2,{4+1/4}) ({2+sqrt(4-1/4)},{1/2}) arc ({asin(1/2/2)}:{-180-asin(1/2/2)}:2);  

\draw [dashed] ({2-sqrt(4-1/4)},{1/2}) arc ({180-asin(1/2/2)}:{asin(1/2/2)}:2);
\draw [dashed] (2,4) -- (2,0);
\draw [->]({2-sqrt(2)},{-sqrt(2)}) --++ (4,4);
\draw (2,0) ++ (-2pt,2pt) --++ (4pt,-4pt);
\draw ({2+sqrt(2)},{sqrt(2)}) ++ (-2pt,2pt) --++ (4pt,-4pt);

\filldraw [draw=blue!85!black, fill=lime, opacity=.4] ({2-sqrt(3-1/4)},{1+1/2}) parabola bend (2,{4+1/4}) ({2-sqrt(4-1/4)},{1/2}) arc ({-180-asin(1/2/2)}:{asin(1/2/2)}:2) ({2+sqrt(4-1/4)},{1/2}) parabola bend (2,{4+1/4}) ({2+sqrt(3-1/4)},{1+1/2}) arc ({asin(1/2/sqrt(3))}:{-180-asin(1/2/sqrt(3))}:{sqrt(3)});
\filldraw [draw=lime!75!black, fill=lime!50!black, opacity=.4] ({2-sqrt(2-1/4)},{2+1/2}) parabola bend (2,{4+1/4}) ({2-sqrt(3-1/4)},{1+1/2}) arc ({-180-asin(1/2/sqrt(3))}:{asin(1/2/sqrt(3))}:{sqrt(3)}) ({2+sqrt(3-1/4)},{1+1/2}) parabola bend (2,{4+1/4}) ({2+sqrt(2-1/4)},{2+1/2}) arc ({asin(1/2/sqrt(2))}:{-180-asin(1/2/sqrt(2))}:{sqrt(2)});
\filldraw [draw=brown!85!black, fill=brown, opacity=.6] ({2-sqrt(1-1/4)},{3+1/2}) parabola bend (2,{4+1/4}) ({2-sqrt(2-1/4)},{2+1/2}) arc ({-180-asin(1/2/sqrt(2))}:{asin(1/2/sqrt(2))}:{sqrt(2)}) ({2+sqrt(2-1/4)},{2+1/2}) parabola bend (2,{4+1/4}) ({2+sqrt(1-1/4)},{3+1/2}) arc ({asin(1/2)}:{-180-asin(1/2)}:1);
\filldraw [draw=brown, fill=brown, opacity=.75] ({2-sqrt(1-1/4)},{3+1/2}) parabola bend (2,{4+1/4}) ({2+sqrt(1-1/4)},{3+1/2}) arc ({asin(1/2)}:{-180-asin(1/2)}:1);

\draw ({2-sqrt(4-1/4)},{1/2}) parabola bend (2,{4+1/4}) ({2+sqrt(4-1/4)},{1/2});
\draw ({2-sqrt(4-1/4)},{1/2}) arc ({-180-asin(1/2/2)}:{asin(1/2/2)}:2);

\node[draw=black, star, fill=yellow,star point ratio=2.25, inner sep=0pt, minimum width=3mm] at (2,4) {};

\draw ({2-sqrt(2)},{-sqrt(2)}) --++ (-2,-2);
\draw [->]({2-sqrt(2)},{-sqrt(2)}) --++ (-2,2);
\draw ({2-sqrt(2)},{-sqrt(2)}) --++ (2,-2);
\draw [->]({2-sqrt(2)},{-sqrt(2)-2}) --++ (0,8.5);

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容