tikz 堆叠磁盘 3D

tikz 堆叠磁盘 3D

我想知道是否可以使用 tikz 绘制这样的 3D 图像?我在这张图片周围添加了一些文字,在 tikz 中看起来很棒,但我无法在 tikz 中绘制这种 3D 图形。而且它周围的阴影对我来说看起来相当复杂。

有什么例子、想法或建议吗?

在此处输入图片描述

谢谢 !

答案1

从任何方面来说都绝对不是完美的,但是无论如何......

\documentclass[tikz,border=5]{standalone}
\tikzset{pics/.cd,
  disc/.style={
    code={
      \fill [white] ellipse [x radius=2, y radius=2/3];
      \path [left color=black!50, right color=black!50, middle color=black!25] 
        (-2+.05,-1.1) arc (180:360:2-.05 and 2/3-.05*2/3) -- cycle;
      \path [top color=black!25, bottom color=white] 
        (0,.05*2/3) ellipse [x radius=2-.05, y radius=2/3-.05*2/3];
      \path [left color=black!25, right color=black!25, middle color=white] 
        (-2,0) -- (-2,-1) arc (180:360:2 and 2/3) -- (2,0) arc (360:180:2 and 2/3);
      \foreach \r in {225,315}
        \foreach \i [evaluate={\s=30;}] in {0,2,...,30}
          \fill [black, fill opacity=1/50] 
            (0,0) -- (\r+\s-\i:2 and 2/3) -- ++(0,-1) 
            arc (\r+\s-\i:\r-\s+\i:2 and 2/3) -- ++(0,1) -- cycle;
      \foreach \r in {45,135}
        \foreach \i [evaluate={\s=30;}] in {0,2,...,30}
          \fill [black, fill opacity=1/50] 
            (0,0) -- (\r+\s-\i:2 and 2/3) 
            arc (\r+\s-\i:\r-\s+\i:2 and 2/3)  -- cycle;
    }
  },
  disc bottom/.style={
    code={
      \foreach \i in {0,2,...,30}
        \fill [black, fill opacity=1/60] (0,-1.1) ellipse [x radius=2+\i/40, y radius=2/3+\i/60];
      \path pic {disc};
    }
  }
}
\begin{document}
\begin{tikzpicture}

\path (0,0) pic {disc bottom} (0,1.25) pic {disc} (0,2.5) pic {disc};

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

恐怕我也忍不住要尝试一下 Asymptote。与 TikZ 解决方案不同,它实际上使用了一个底层 3D 模型。特别是,顶部周围的“白色圆环”由于圆角和 Asymptote 的着色功能而自然出现。

\documentclass[margin=10pt,convert]{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=disk}
    settings.outformat = "png";
    settings.render=16;
    unitsize(2cm);
    import three;
    import roundedpath;
    currentprojection = orthographic(0,4,1);

    int nslices = 20;
    pen colorfunction(int u, real v) {
        real t = (v/nslices)*4pi;
        static pen dark = gray(0.3);
        static pen light = white;
        return interp(dark, light, (sin(t)+1)/2);
    }

    real radius = 2.0, height = 1.0;

    path3 to_revolve = path3(roundedpath((0,0) -- (radius,0) -- (radius,height) -- (0.9 radius, height) -- (0,height), R=0.05), YZplane);
    surface disk = surface(to_revolve, c=O, axis=Z, n=nslices, color = colorfunction);
    draw(disk);

    pen undercolorfunction(int u, real v) {
        pen overpen = colorfunction(u,v);
        real r = point(to_revolve, u).y;
        return interp(black, overpen, (r/radius)^5);
    }

    surface underdisk = surface(to_revolve, c=O, axis=Z, n=nslices, color=undercolorfunction);

    draw(shift(-1.2*height*Z)*underdisk);
    draw(shift(-2.4*height*Z)*underdisk);

\end{asypicture}
\end{document}

结果:

答案3

我研究了马克的解决方案,使其看起来更类似于原始图片。

\documentclass[tikz,border=5]{standalone}

\usetikzlibrary{fadings}
\tikzfading[name=fade out,
inner color=transparent!0, outer color=transparent!100]

\def\factor{4}
\def\xradius{2}
\def\yradius{2/\factor}
\def\height{1.05cm}
\def\xandy{2 and 2/\factor}

\tikzset{
  pics/.cd, %
  disc/.style ={
    code = {
      %% the foundation
      \path [fill=black!15] (-\xradius,0) -- (-\xradius,-\height) arc
      (180:360:\xandy) -- (\xradius,0) arc (0:180:\xandy);%
      \path [top color=black!25, bottom color=white, opacity=0.2] (0,0) ellipse
      [x radius=\xradius, y radius =\yradius];%
      \path [left color=black!25, right color=black!15] (-\xradius,0) --
      (-\xradius,-\height) arc (180:240:\xandy) -- +(0,\height) arc
      (240:180:\xandy);%
      \path [left color=black!15, right color=black!30] (\xradius,0) --
      (\xradius,-\height) arc (360:320:\xandy) -- +(0,\height) arc
      (320:360:\xandy);

      %% rays in front
      \foreach \col/\r/\shift/\stop/\opacity in {%
        black/205/25/20/100, %
        black/295/35/30/100, %
        black/295/30/30/200, %
        black/295/25/20/300, %
        white/245/14/14/100, %
        white/245/12/12/20, %
        white/245/10/10/10} {%
        \foreach \i [evaluate={\opposite=\r-180;}] in {0,1,...,\stop}{%
          \fill [\col, fill opacity = 1/\opacity] (\opposite:0.1 and
          0.1/\factor) -- (\r+\shift-\i:\xandy) -- ++(0,-\height) arc
          (\r+\shift-\i:\r-\shift+\i:\xandy) -- +(0,\height) -- cycle; }}

      %% rays in back
      \foreach \r/\shift/\stop/\opacity in {%
        25/25/20/100, %
        115/35/3/150,%
        115/30/23/100} {%
        \foreach \i [evaluate={\opposite=\r-180;}] in {0,1,...,\stop}{%
          \fill [black, fill opacity = 1/\opacity] (\opposite:0.1 and 0.1/\factor) --
          (\r+\shift-\i:\xandy) arc (\r+\shift-\i:\r-\shift+\i:\xandy) --
          cycle; }}

      %% masking the four edges in the center
      \foreach \i in {0.1, 0.2, ..., 0.4}%
      \fill[black!15, opacity=0.7, path fading=fade out] 
      (0,0) ellipse[x radius=\i, y radius =\i/\factor];

      %% the light and the dark arcs
      \foreach \i [evaluate={\start=185+10*\i; \finish=355-10*\i;}]%
      in {0.1, 0.2, ..., 1.5}{%
        \draw[white, opacity=0.04, line width=\i, yshift=0.02cm]
        (\start:\xandy) arc (\start:\finish:\xandy);

        \draw[black!80, opacity=0.05, line width=\i, yshift=-\height]
        (\start:\xandy) arc (\start:\finish:\xandy); }
    }
  },% 
  disc bottom/.style = {
    code = {
      \foreach \i/\opacity in {%
        1/20,2/20,3/20,4/30,5/35,6/40,7/60,8/80,9/100,10/100,11/100,12/100}%
        \fill [black, fill opacity = 1/\opacity, yshift=-0.03cm] (0,-\height)
        ellipse [x radius = \xradius+\i/40, y radius = \yradius+\i/20/\factor]; 
      \path pic {disc};
    }
  },%
  disc top/.style = {
    code = {
      \foreach \i/\opacity in {%
        2/60, 3/55, 4/50,5/40, 6/35, 7/30, 8/20, 9/20, 10/20, 11/20, 12/20,
        13/20, 14/20, 15/20, 16/20, 17/20, 18/20, 19/20, 20/20, 21/20, 22/20,
        23/20, 24/20, 25/20, 26/20}%
        \fill [black, fill opacity = 1/\opacity, yshift=-0.35cm] (0,-\height)
        ellipse [x radius = \xradius-\i/40, y radius = \yradius-\i/20/\factor];
      \path pic {disc};
    }
  }
}

\begin{document}
\begin{tikzpicture}
  \path (0,0) pic {disc bottom} (0,1.4) pic {disc top} (0,2.8) pic {disc top};
\end{tikzpicture}
\end{document}

更新:尺寸是可参数化的。但您可能需要相应地移动圆盘和下面的阴影。

堆叠的光盘

相关内容