我使用 Tikz 生成了此 2D 图。我想通过绕 z 轴旋转来获取其 3D 版本。是否有任何 Tikz 特殊命令可以做到这一点?谢谢
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=6]
\draw[-] (0,2,0)--(-0.5,1,0).. controls (-1,0,0) and (1,0,0)..
(0.5,1,0)--(0,2,0);
\draw[dashed](0,-0.1,0)--(0,2.1,0);
\node [above] at (0,2.1,0) {$\boldsymbol{Z}$};
\end{tikzpicture}
\end{center}
\end{document}
答案1
是的,有。tikz-3dplot
使用3d
自动加载的库。旋转角度是\tdplotsetmaincoords{90}{70}
以下 MWE 中的第二个参数:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{amsmath}
\begin{document}
\begin{center}
\tdplotsetmaincoords{90}{70}
\begin{tikzpicture}[tdplot_main_coords,scale=6,canvas is xz plane at y=0]
\draw[-] (0,2)--(-0.5,1).. controls (-1,0) and (1,0)..
(0.5,1)--(0,2);
\draw[dashed](0,-0.1)--(0,2.1);
\node [above] at (0,2.1) {$\boldsymbol{Z}$};
\end{tikzpicture}
\end{center}
\end{document}
动画说明旋转角度的含义。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{amsmath}
\begin{document}
\foreach \X in {5,15,...,355}
{\tdplotsetmaincoords{90}{\X}
\begin{tikzpicture}[tdplot_main_coords,scale=6]
\path[use as bounding box,tdplot_screen_coords] (-1,-0.5) rectangle (1,2.5);
\begin{scope}[canvas is xz plane at y=0]
\draw[-] (0,2)--(-0.5,1).. controls (-1,0) and (1,0)..
(0.5,1)--(0,2);
\draw[dashed](0,-0.1)--(0,2.1);
\node [above] at (0,2.1) {$\boldsymbol{Z}$};
\end{scope}
\end{tikzpicture}}
\end{document}
这可用于填充表面。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[scale=6]
\tdplotsetmaincoords{90}{0}
\path[use as bounding box,tdplot_screen_coords] (-1,-0.5) rectangle (1,2.5);
\foreach \X [count=\Y] in {0,1,...,89}
{\tdplotsetrotatedcoords{00}{0}{\X}
\pgfmathtruncatemacro{\ccol}{100-0.7*\Y}
\begin{scope}[tdplot_rotated_coords,canvas is xz plane at y=0]
\path[fill=blue!\ccol] (0,2)--(-0.5,1).. controls (-1,0) and (1,0)..
(0.5,1)--(0,2);
\end{scope} }
\draw[dashed](0,-0.1)--(0,2.1);
\node [above] at (0,2.1) {$\boldsymbol{Z}$};
\end{tikzpicture}
\end{document}
附录: 至于澄清的问题:据我所知,没有一个简单的开关可以为您提供表面。但是,如果您有一个近似贝塞尔曲线的函数,则可以使用它pgfplots
来绘制旋转表面。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{amsmath}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[unit vector ratio=1 1 1,scale=6,hide axis,colormap/viridis]
\addplot3[surf,shader=interp,z buffer=sort,domain y=0:180,domain=0:360]
({2*sin(x)*sin(y)/3},{2*cos(x)*sin(y)/3},{0.5*(1+ifthenelse(abs(y)<90,(90-abs(y))*6/180,0.7*cos(y)))});
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}