我尝试绘制一个弯曲的 3D 圆锥体,其顶部和底部部分分别旋转 45 度和 -45 度。由于每条边都没有相互连接,因此似乎行不通。以下是代码:
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{20}{0}
\begin{tikzpicture}[tdplot_main_coords,declare
function={r1=2;r2=1.25;h=10;curvature=5;bd=0;}]
\path[fill=gray!50] plot[variable=\x,samples at={0,60,...,300},rotate around={-45:(0,0,0)}]
({r1*cos(\x)},0,{r1*sin(\x)});
\draw[thick,dashed] plot[variable=\x,samples at={0,60,120,180},rotate around={-45:(0,0,0)}]
({r1*cos(\x)},0,{r1*sin(\x)});
\draw[thick] plot[variable=\x,samples at={180,240,300,0},rotate around={-45:(0,0,0)}]
({r1*cos(\x)},0,{r1*sin(\x)});
\foreach \X in {60,120,...,360}
{\draw[thick] \ifnum \X<180 [dashed] \fi
plot[variable=\x,domain=r2:r1]
({\x*cos(\X)-curvature*(\x-r1)*(\x-r2)*cos(bd)},{-h*(\x-r1)/(r1-r2)},
{\x*sin(\X)-curvature*(\x-r1)*(\x-r2)*sin(bd)});}
\path[fill=gray!25,fill opacity=0.8,] plot[variable=\x,samples at={0,60,...,300},rotate around={45:(0,h,0)}]
({r2*cos(\x)},h,{r2*sin(\x)});
\draw[thick] plot[variable=\x,samples at={0,60,120,180},rotate around={45:(0,h,0)}]
({r2*cos(\x)},h,{r2*sin(\x)});
\draw[thick] plot[variable=\x,samples at={180,240,300,0},rotate around={45:(0,h,0)}]
({r2*cos(\x)},h,{r2*sin(\x)});
\end{tikzpicture}
\end{document}
答案1
如果你能公开你的代码源就好了。上面的代码是为了完成某一特定任务,它对此有效。这里你需要一个稍微不同的方法。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{20}{0}
\begin{tikzpicture}[tdplot_main_coords,declare
function={r1=2;r2=1.25;h=10;curvature=5;bd=0;rot=0.125;}]
\foreach \X [count=\Y] in {60,120,...,360}
{\draw[thick] \ifnum \X<180 [dashed] \fi
plot[variable=\x,domain=r2:r1]
({\x*cos(\X)-curvature*(\x-r1)*(\x-r2)*cos(bd)},{h*(1+rot*cos(\X))*(\x-(r1+r2)/2)/(r2-r1)},
{\x*sin(\X)-curvature*(\x-r1)*(\x-r2)*sin(bd)})
coordinate (b-\Y)
({r2*cos(\X)-curvature*(r2-r1)*(r2-r2)*cos(bd)},{h*(1+rot*cos(\X))*(r2-(r1+r2)/2)/(r2-r1)},
{r2*sin(\X)-curvature*(r2-r1)*(r2-r2)*sin(bd)}) coordinate (t-\Y);}
\begin{scope}[on background layer]
\path[fill=gray!50] plot[variable=\x,samples at={1,...,6}] (b-\x);
\draw[thick,dashed] plot[variable=\x,samples at={6,1,2,3}] (b-\x);
\draw[thick] plot[variable=\x,samples at={3,4,5,6}] (b-\x);
\end{scope}
\path[fill=gray!25,fill opacity=0.8,] plot[variable=\x,samples at={1,...,6}] (t-\x);
\draw[thick] plot[variable=\x,samples at={1,...,6,1}] (t-\x);
\end{tikzpicture}
\end{document}