使用 TikZ 填充复杂的 3D 形状

使用 TikZ 填充复杂的 3D 形状

我正在尝试重现一张图片,以便可以修改其中的某些方面。这是图片:

在此处输入图片描述

我怎样才能填充 3d 形状之间以形成外壳?

这是我目前所拥有的:

\documentclass{scrbook}
\usepackage{graphicx}
\usepackage{float}
\usepackage[usenames, dvipsnames, svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, decorations.pathmorphing, positioning, patterns, intersections}
\usepackage{tikz-3dplot}
\usetikzlibrary{hobby}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\begin{document}

\begin{tikzpicture}
    \tdplotsetrotatedcoords{5}{55}{0}
    \begin{scope}[tdplot_rotated_coords]
    \draw[black, name path = A] (0,1,0) -- (3,3,0) arc[canvas is yz plane at x=3, start angle=90, end angle=-150, radius=3] coordinate(C1) -- (0,0,-1) -- (0,0,0) -- (0,1,0);
    \draw[black, name path = B](3,3,0) -- (5,3,0) arc[canvas is yz plane at x=5, radius=3, start angle=90, end angle=-150] coordinate(C3)-- (C1) arc[canvas is yz plane at x=3, start angle=-150, end angle=90, radius=3] -- cycle;
    \draw[red](3,3.1,0) arc[canvas is yz plane at x=3, radius=3.1, start angle=90, end angle=-150] coordinate (C2);
    \draw[black, name path = C](3,3.1,0) -- (5,3.1,0) arc[canvas is yz plane at x=5, radius=3.1, start angle=90, end angle=-150] coordinate(C4) -- (C2) arc[canvas is yz plane at x=3, start angle=-150, end angle=90, radius=3.1] -- cycle;
    \draw[black,name path = D] (C1) --(C2);
    \draw[black, name path =E] (3,3,0) -- (3,3.1,0);
    \draw[black, name path= F] (5,3,0) -- (5,3.1,0);
    \draw[black, name path = G] (C3) -- (C4);
    \end{scope}
\end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

答案1

免责声明

  1. Z 没有真正的 3D 引擎,所以你需要自己做很多事情。
  2. 以下代码专门针对您的视角。原则上,可以使其适用于更多/所有视角,但这需要付出更多努力。
  3. 我按照您的选择隐含地概述的路径加载了 pfplots 库 fillbetween。原则上,您可以手动计算相关的交点并绘制相关路径,但确实在这里使用该库会更方便一些。

说了这么多,下面是代码。

\documentclass[border=3.14mm]{standalone}
\usepackage[usenames, dvipsnames, svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, decorations.pathmorphing,
positioning, patterns, intersections,shadings}
\usepackage{tikz-3dplot}
\usetikzlibrary{hobby}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\begin{document}
\tdplotsetmaincoords{00}{00}
\begin{tikzpicture}
    \tdplotsetrotatedcoords{5}{55}{0}
    \begin{scope}[tdplot_rotated_coords]
    \draw[black, name path = A] (0,1,0) -- (3,3,0) arc[canvas is yz plane at x=3, start angle=90, end angle=-150, radius=3] coordinate(C1) -- (0,0,-1) -- (0,0,0) -- (0,1,0);
    \draw[black, name path = B](3,3,0) coordinate (C5) -- (5,3,0) arc[canvas is yz plane at x=5,
radius=3, start angle=90, end angle=-150] coordinate(C3)
coordinate[pos=0.75] (t1) -- (C1) arc[canvas is yz
plane at x=3, start angle=-150, end angle=90, radius=3] 
coordinate[pos=0.25] (t2) coordinate (C6)-- cycle;
    % the following arc may not be necessary
    \draw[black](3,3.1,0) arc[canvas is yz plane at x=3, radius=3.1, start
angle=90, end angle=-150] coordinate (C2);
    \draw[name path = C](3,3.1,0) -- (5,3.1,0) 
    arc[canvas is yz plane at x=5, radius=3.1, start angle=90, end angle=-150]
    coordinate(C4) coordinate[pos=0.75] (b1) -- (C2) arc[canvas is yz plane at x=3, start angle=-150, end
    angle=90, radius=3.1] coordinate[pos=0.25] (b2) -- cycle;
    \path[name path=I] (t2) -- (t1);
    \shade[bottom color=gray,top color=black,
        intersection segments={of=B and I,sequence={L1--R0--L0}}];  
    \draw[name path=H] (b2) -- (b1);
    \shade[bottom color=black,top color=gray,intersection segments={of=C and
    H,sequence={L2--R0}}];
    \fill[gray!60]  (C1) --(C2) -- (C4) -- (C3) -- cycle;
    \draw[name path = D] (C1) --(C2);
    \draw[name path = G] (C4) -- (C3);
    \fill[gray!20!black]  (3,3,0) -- (3,3.1,0) -- (5,3.1,0) -- (5,3,0) -- cycle;
    \draw[black, name path=E] (3,3,0) -- (3,3.1,0);
    \draw[black, name path=F] (5,3,0) -- (5,3.1,0);
    % G and F
    \fill[gray!60] (5,3.1,0) arc[canvas is yz plane at x=5,radius=3.1,
    start angle=90, end angle=-150] -- (C4) -- (C3)
    arc[canvas is yz plane at x=5, radius=3.0, start angle=-150, 
    end angle=90] -- (5,3,0) ;
    \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

能画出屏幕截图中显示的完整形状吗?原则上可以,但工作量会非常大。

相关内容