在 Tikz 中创建 Shell 元素

在 Tikz 中创建 Shell 元素

我准备写一篇硕士论文(机械工程)。我对 还不熟悉tikz,之前只拍过 2 张tikz照片。但是,我看到了 的强大功能和非常漂亮的图形效果,tikz想学习它。我花了一整天时间研究如何创建一个带有参考中间面的双曲面壳单元,以便将其放入我的论文中。这就是我现在所拥有的(主要基于反复试验)。

\begin{figure}  % aIGAs element
\centering
% Rotation around x-axis and z-axis [70/45]
\tdplotsetmaincoords{60}{45}
\begin{tikzpicture}[scale=1.0, tdplot_main_coords]

% Define
\def \thickness {1.0}
\def \materialpointx {0.0}
\def \materialpointy {0.0}
\def \materialpointz {0.0}
\def \shellx {10.0}
\def \shelly {10.0}

% Define shell midsurface corners
\coordinate (midsurf0) at (-\shellx/2,-\shelly/2,0);
\coordinate (midsurf1) at (+\shellx/2,-\shelly/2,0);
\coordinate (midsurf2) at (+\shellx/2,+\shelly/2,0);
\coordinate (midsurf3) at (-\shellx/2,+\shelly/2,0);
% Define shell topsurface corners
\coordinate (midsurf0t) at (-\shellx/2,-\shelly/2,+\thickness/2);
\coordinate (midsurf1t) at (+\shellx/2,-\shelly/2,+\thickness/2);
\coordinate (midsurf2t) at (+\shellx/2,+\shelly/2,+\thickness/2);
\coordinate (midsurf3t) at (-\shellx/2,+\shelly/2,+\thickness/2);

% Define shell bottomsurface corners
\coordinate (midsurf0b) at (-\shellx/2,-\shelly/2,-\thickness/2);
\coordinate (midsurf1b) at (+\shellx/2,-\shelly/2,-\thickness/2);
\coordinate (midsurf2b) at (+\shellx/2,+\shelly/2,-\thickness/2);
\coordinate (midsurf3b) at (-\shellx/2,+\shelly/2,-\thickness/2);

% Define shell midsurface [lower, right, upper, left]
% \tdplotdefinepoints(CenterPoint)(StartPoint)(EndPoint) [x,y,z]
\tdplotdefinepoints(0,-\shelly/2,-8.65)(-\shellx/2,-\shelly/2,0)    (+\shellx/2,-\shelly/2,0);
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
\tdplotdefinepoints(+\shellx/2,0,-8.65)(+\shellx/2,-\shelly/2,0)(+\shellx/2,+\shelly/2,0);
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
\tdplotdefinepoints(0,+\shelly/2,-8.65)(-\shellx/2,+\shelly/2,0)(+\shellx/2,+\shelly/2,0);
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
\tdplotdefinepoints(-\shellx/2,0,-8.65)(-\shellx/2,-\shelly/2,0)(-        \shellx/2,+\shelly/2,0);
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
% Define shell topsurface [lower, right, upper, left]
% \tdplotdefinepoints(CenterPoint)(StartPoint)(EndPoint) [x,y,z]
\tdplotdefinepoints(0,-\shelly/2,-8.65 + \thickness/2)(-\shellx/2,-    \shelly/2,\thickness/2)(+\shellx/2,-\shelly/2,\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(+\shellx/2,0,-8.65+\thickness/2)(+\shellx/2,-    \shelly/2,\thickness/2)(+\shellx/2,+\shelly/2,\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(0,+\shelly/2,-8.65+\thickness/2)(-    \shellx/2,+\shelly/2,\thickness/2)(+\shellx/2,+\shelly/2,\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(-\shellx/2,0,-8.65+\thickness/2)(-\shellx/2,-\shelly/2,\thickness/2)(-\shellx/2,+\shelly/2,\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
% Define shell bottmsurface [lower, right, upper, left]
% \tdplotdefinepoints(CenterPoint)(StartPoint)(EndPoint) [x,y,z]
tdplotdefinepoints(0,-\shelly/2,-8.65 - \thickness/2)(-\shellx/2,-    \shelly/2,-\thickness/2)(+\shellx/2,-\shelly/2,-\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(+\shellx/2,0,-8.65-\thickness/2)(+\shellx/2,-\shelly/2,-\thickness/2)(+\shellx/2,+\shelly/2,-\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(0,+\shelly/2,-8.65-\thickness/2)(-\shellx/2,+\shelly/2,-\thickness/2)(+\shellx/2,+\shelly/2,-\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};

\tdplotdefinepoints(-\shellx/2,0,-8.65-\thickness/2)(-\shellx/2,-\shelly/2,-\thickness/2)(-\shellx/2,+\shelly/2,-\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\draw[black, ultra thin] (midsurf0b) -- (midsurf0t);
\draw[black, ultra thin] (midsurf1b) -- (midsurf1t);
\draw[black, ultra thin] (midsurf2b) -- (midsurf2t);
\draw[black, ultra thin] (midsurf3b) -- (midsurf3t);
\end{tikzpicture}
\end{figure}

我觉得这个壳看起来不太真实,因为“背面”看起来不像我现在的样子。此外,我想填充中间表面(灰色)。我在谷歌上搜索了很久,但找不到任何相关信息。当壳准备好后,我只需要在其中放置一些向量(在某个点与表面相切)。另一个棘手的部分是,我需要与壳的边界完全匹配的曲线坐标,但我真的不知道如何让它正常工作。

有人知道怎么做吗?非常感谢!

答案1

这个答案有两个目的。在第一部分中,我稍微整理了一下你的代码,以便它能够运行。第二部分是试图说服你熟悉另一个包:pgfplots。这是因为它内置了一些着色器,它们相当不错(只要你不将它们与 asymptote 进行比较 ;-)。

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\begin{document}
% Rotation around x-axis and z-axis [70/45]
\tdplotsetmaincoords{60}{45}
\begin{tikzpicture}[scale=1.0, tdplot_main_coords]

% Define
\def\thickness{1.0}
\def\materialpointx{0.0}
\def\materialpointy{0.0}
\def\materialpointz{0.0}
\def\shellx{10.0}
\def\shelly{10.0}

% Define shell midsurface corners
\coordinate (midsurf0) at (-\shellx/2,-\shelly/2,0);
\coordinate (midsurf1) at (\shellx/2,-\shelly/2,0); %removed leading + signs
\coordinate (midsurf2) at (\shellx/2,\shelly/2,0); %removed leading + signs
\coordinate (midsurf3) at (-\shellx/2,\shelly/2,0);%removed leading + signs 
% Define shell topsurface corners
\coordinate (midsurf0t) at (-\shellx/2,-\shelly/2,+\thickness/2);
\coordinate (midsurf1t) at (\shellx/2,-\shelly/2,\thickness/2);%removed leading + signs
\coordinate (midsurf2t) at (\shellx/2,\shelly/2,\thickness/2);%removed leading + signs
\coordinate (midsurf3t) at (-\shellx/2,\shelly/2,\thickness/2);%removed leading + signs

% Define shell bottomsurface corners
\coordinate (midsurf0b) at (-\shellx/2,-\shelly/2,-\thickness/2);
\coordinate (midsurf1b) at (+\shellx/2,-\shelly/2,-\thickness/2);
\coordinate (midsurf2b) at (+\shellx/2,+\shelly/2,-\thickness/2);
\coordinate (midsurf3b) at (-\shellx/2,+\shelly/2,-\thickness/2);

% Define shell midsurface [lower, right, upper, left]
% \tdplotdefinepoints(CenterPoint)(StartPoint)(EndPoint) [x,y,z]
\tdplotdefinepoints(0,-\shelly/2,-8.65)(-\shellx/2,-\shelly/2,0)(\shellx/2,-\shelly/2,0);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
\tdplotdefinepoints(\shellx/2,0,-8.65)(+\shellx/2,-\shelly/2,0)(\shellx/2,\shelly/2,0);
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
\tdplotdefinepoints(0,\shelly/2,-8.65)(-\shellx/2,+\shelly/2,0)(\shellx/2,\shelly/2,0);
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
\tdplotdefinepoints(-\shellx/2,0,-8.65)(-\shellx/2,-\shelly/2,0)(-\shellx/2,\shelly/2,0);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thick]{10}{}{};
% Define shell topsurface [lower, right, upper, left]
% \tdplotdefinepoints(CenterPoint)(StartPoint)(EndPoint) [x,y,z]
\tdplotdefinepoints(0,-\shelly/2,-8.65 + \thickness/2)(-\shellx/2,-    \shelly/2,\thickness/2)(\shellx/2,-\shelly/2,\thickness/2);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(+\shellx/2,0,-8.65+\thickness/2)(\shellx/2,-    \shelly/2,\thickness/2)(\shellx/2,\shelly/2,\thickness/2);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(0,+\shelly/2,-8.65+\thickness/2)(-    \shellx/2,\shelly/2,\thickness/2)(\shellx/2,\shelly/2,\thickness/2);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(-\shellx/2,0,-8.65+\thickness/2)(-\shellx/2,-\shelly/2,\thickness/2)(-\shellx/2,\shelly/2,\thickness/2);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
% Define shell bottmsurface [lower, right, upper, left]
% \tdplotdefinepoints(CenterPoint)(StartPoint)(EndPoint) [x,y,z]
\tdplotdefinepoints(0,-\shelly/2,-8.65 - \thickness/2)(-\shellx/2,-    \shelly/2,-\thickness/2)(+\shellx/2,-\shelly/2,-\thickness/2);
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(+\shellx/2,0,-8.65-\thickness/2)(\shellx/2,-\shelly/2,-\thickness/2)(\shellx/2,\shelly/2,-\thickness/2);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\tdplotdefinepoints(0,+\shelly/2,-8.65-\thickness/2)(-\shellx/2,\shelly/2,-\thickness/2)(\shellx/2,\shelly/2,-\thickness/2);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};

\tdplotdefinepoints(-\shellx/2,0,-8.65-\thickness/2)(-\shellx/2,-\shelly/2,-\thickness/2)(-\shellx/2,\shelly/2,-\thickness/2);%removed leading + signs
\tdplotdrawpolytopearc[black,ultra thin]{10}{}{};
\draw[black, ultra thin] (midsurf0b) -- (midsurf0t);
\draw[black, ultra thin] (midsurf1b) -- (midsurf1t);
\draw[black, ultra thin] (midsurf2b) -- (midsurf2t);
\draw[black, ultra thin] (midsurf3b) -- (midsurf3t);
\end{tikzpicture}

\pgfplotsset{colormap={myblackwhite}{gray(0cm)=(0.6); gray(1cm)=(0.8)}
,width=12cm,compat=1.15,view={0}{10}} % notice that because of the redefinition
% of xscale and yscale below the view angle does not have its original meaning
\tikzset{declare function={f(\x,\y)=-(0.3*(\x-2)*(\x-2));}}
\tikzset{declare function={g(\x,\y)=-(0.3*(\x-10)*(\x-10)+0.3*64);}}
\begin{tikzpicture}[yscale=1,xscale=1.2,opacity=0.7] 
\begin{axis}[samples=50,hide axis,shader=interp]
    \path (10,0,0) -- (10,10,0);
    \addplot3[domain y=0:1,domain=-10:0] [surf] {f(-x,y)};
    \addplot3[domain y=0:1,domain=0:10] [surf] {f(x,y)};
    \addplot3[very thick,domain=-10:0,samples y=0] ({\x},0.5,{f(-\x,0)});
    \addplot3[very thick,domain=0:10,samples y=0] ({\x},0.5,{f(\x,0)});
    \addplot3[domain y=0:1,domain=-10:0] [surf] {g(-x,y)};
    \addplot3[domain y=0:1,domain=0:10] [surf] {g(x,y)};
    \addplot3[very thick,domain=-10:0,samples y=0] ({\x},0.5,{g(-\x,0)});
    \addplot3[very thick,domain=0:10,samples y=0] ({\x},0.5,{g(\x,0)});
\end{axis}  
\end{tikzpicture}
\end{document}

您的代码(经过一些轻微的清理): 在此处输入图片描述

使用 pgfplots: 在此处输入图片描述

说实话,我不知道如何在 Ti 中重现这些阴影Z 无需pgfplots直截了当的方式。

编辑:当然,单个圆弧要简单得多。

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15} 
\begin{document}
\pgfplotsset{colormap={myblackwhite}{gray(0cm)=(0.4); gray(1cm)=(0.8)}
,width=12cm,compat=1.15,view={0}{10}} % notice that because of the redefinition
% of xscale and yscale below the view angle does not have its original meaning
\tikzset{declare function={f(\x,\y)=-(0.3*0.64*(\x)*(\x));}}
\tikzset{declare function={g(\x,\y)=-(0.3*(\x-10)*(\x-10)+0.3*64);}}
\begin{tikzpicture}[yscale=1,xscale=1.2,opacity=0.7] 
\begin{axis}[hide axis,shader=interp]
    \addplot3[domain y=0:1,domain=-10:10] [surf] {f(x,y)};
    \addplot3[very thick,domain=-10:10,samples y=0] ({\x},0.5,{f(\x,0)});
    \addplot3[domain y=0:1,domain=-10:0] [surf] {g(-x,y)};
    \addplot3[domain y=0:1,domain=0:10] [surf] {g(x,y)};
    \addplot3[very thick,domain=-10:0,samples y=0] ({\x},0.5,{g(-\x,0)});
    \addplot3[very thick,domain=0:10,samples y=0] ({\x},0.5,{g(\x,0)});
\end{axis}  
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容