TikZ:阴影、嵌套、倒锥体(相关速率图)

TikZ:阴影、嵌套、倒锥体(相关速率图)

我正在阅读有关相关速率(微分学)的书籍,目前正在研究倒置锥形水箱问题。在我读的教科书中,有一张相当漂亮的情况图。

在此处输入图片描述

我和 Ti 搞了点小事情过去,我曾使用过 Z 的渐变和阴影,并且发现界面非常难用。制作这种涉及渐变、阴影和其他杂乱元素的图表超出了我能想到的任何方法(因此,我放弃发布 MWE)。

我怎样才能重新创建上图中的圆锥体?我相信,如果圆锥体完成了,我就能完成图表。请注意,我并不反对涉及 LaTeX 的其他图形相关软件包的答案,但 TiZ 是我目前唯一研究过的,所以如果你走那条路的话,多一点解释和/或链接可能不会有坏处:)

谢谢!

答案1

使用普通的 Ti 可能很难实现阴影效果Z/PGFPlots。你最好使用渐近线而是。不过,我已经写了一个 Asymptote 和 TiZ/PGFPlots 解决方案。

渐近线解

请注意,我花了一整夜的时间学习了 Asymptote 的基础知识,才想出了这个解决方案(我以前从未使用过它)。从美学上讲,它可以改进。红色文本只是为了显示使用的坐标(位于代码末尾)。最初,我使用作为起点,始终应该给予信任:)。

渐近线输出

\documentclass[border=1cm]{standalone}
\usepackage{asypictureB}

\begin{document}
    \begin{asypicture}{name=ConeDiagram}
        unitsize(1cm);
        import solids;
        settings.render = 0;
        
        currentprojection = orthographic(0, 180, -45, up = -Z); //view
        pen thick = linewidth(2pt);
        
        real r = 5;     // Radius of larger cone
        real h = 10;    // Height of larger cone
        // The next coordinates represents the larger cone
        triple origin = (0, 0, 0);
        triple coneCenter = (0, 0, h/2);
        triple coneTip = (0, 0, h);
        triple largerConeRadius=(r,0,0);
        
        // Creating the two cones
        revolution largeCone = cone(origin, r, h, axis = Z);
        revolution smallCone = cone(coneCenter, r/2, h/2, axis = Z);
        // Drawing the two cones on screen
        // Use the following for light options: Headlamp, Viewport, White or nolight.
        draw(surface(largeCone), surfacepen = white, light = Viewport);
        draw(surface(smallCone), surfacepen = lightgreen, light = Viewport);
        
        // Drawing the border around the smaller cone
        skeleton s;
        largeCone.transverse(
            s, reltime(largeCone.g, abs(coneCenter) / h), currentprojection
        );
        triple smallConeRadius = relpoint(
            largerConeRadius -- coneTip, abs(coneCenter) / h
        );
        draw(s.transverse.back, dashed + green + linewidth(1pt));
        draw(s.transverse.front, green + linewidth(1pt));
        
        // The radius lines (from the center of the cone to the edge)
        draw(
            L = Label("$5f(t)$", position = Relative(0.5), align = N, black), 
            origin -- largerConeRadius, white + thick
        );
        draw(
            L = Label("$x$", position=Relative(0.5), align = N, black), 
            coneCenter -- smallConeRadius, white + thick
        );
        
        // Vertical line through the middle of the cone
        draw(coneTip -- origin, yellow + thick);
        
        // Drawing bottom-right line in the diagram
        draw(coneTip -- (r + 1, 0, h), red + thick);
        triple smallConeVerticalLineBottomCoord=(r/2, 0, h);
        
        // Vertical line denoting the smaller cone
        triple smallConeVericalLineTop = (
            smallConeRadius.x + 0.5, smallConeRadius.y, smallConeRadius.z
        );
        triple smallConeVericalLineBottom = ((r / 2) + 0.5, 0, h);
        draw(
            L = Label(
                "$y$", align=(0, 0), position = MidPoint, 
                filltype = Fill(white), black
            ), 
            smallConeVericalLineBottom -- smallConeVericalLineTop, blue, Arrows3()
        );
        
        // Vertical line denoting the larger cone
        triple largeConeVericalLineTop = (
            largerConeRadius.x + 0.5, largerConeRadius.y, largerConeRadius.z
        );
        triple largeConeVericalLineBottom = (r + 0.5, 0, h);
        draw(
            L = Label(
                "$10(ft)$", align=(0, 0), position = MidPoint, 
                filltype = Fill(white), black
            ), 
            largeConeVericalLineBottom -- largeConeVericalLineTop, blue, Arrows3()
        );
        
        // The labels of the important coordinates used
        dot(Label("Origin", align = Z, red), origin);
        dot(Label("$AAA$", align = Z, red), smallConeRadius);
        dot(Label("$BBB$", align = Z, red), largerConeRadius);
        dot(Label("$CCC$", align = Z, red), coneCenter);
        dot(Label("$DDD$", align = Z, red), coneTip);
        dot(Label("$EEE$", align = N, red), smallConeVericalLineTop);
        dot(Label("$FFF$", align = Z, red), smallConeVericalLineBottom);
        dot(Label("$GGG$", align = N, red), largeConeVericalLineTop);
        dot(Label("$HHH$", align = Z, red), largeConeVericalLineBottom);
    \end{asypicture}
\end{document}

Z 解决方案

输出

\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{colormaps}
\usetikzlibrary{arrows.meta}
\tikzset{%
  customTip/.tip={stealth[angle=0:4pt]Bar[sep=1pt,width=10pt]},
}
% Custom colours used
\definecolor{lightBlue}{rgb}{0.03, 0.91, 0.87}
\definecolor{darkBlue}{rgb}{0.0, 0.75, 1.0}

% Formula for the cone is copied from http://pgfplots.sourceforge.net/gallery.html (example 169)
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            view={0}{22.5},
            hide axis, axis lines=center,
            clip=false,
            domain=0.0075:1, y domain=0:2*pi,
            xmin=-1.25, xmax=1.25,
            ymin=-1.25, ymax=1.25,
            ymin=-1.25, ymax=1.25,
            samples=45  % The more samples, the sharper the diagram which takes longer to render
        ]
            % Larger cone 
            \addplot3 [surf, shader=interp, 
                mesh/interior colormap={outerConeColourMap}{
                    color=(gray)                % bottom colour
                    color=(lightgray) 
                    color=(gray) 
                    color=(darkgray) 
                    color=(gray)                % top colour
                },
                mesh/interior colormap thresh=1
            ] ({x*cos(deg(y))}, {x*sin(deg(y))}, {x});
             % Smaller cone
            \addplot3 [surf, shader=interp, 
                mesh/interior colormap={innerConeColourMap}{
                    color=(darkBlue)    % bottom colour
                    color=(lightBlue)
                    color=(darkBlue)    % top colour
                },
                mesh/interior colormap thresh=1
                ] ({x/2*cos(deg(y))}, {x/2*sin(deg(y))}, {x/2});
            % Generating points to refer to later.
            \coordinate (origin) at (0, 0, 0);
            \coordinate (bottomConeLeft) at (0.05, 0, 0);
            \coordinate (middleConeLeft) at (0, 3, 0);
            \coordinate (topConeLeft) at (0, 6, 0);
            %
            \coordinate (bottomConeRight) at (1.25, 0, 0);
            \coordinate (middleConeRight) at (0.5, 3, 0);
            \coordinate (topConeRight) at (1, 6, 0);
            %
            % Horizontal line at the bottom of cone
            \draw[blue, very thick](bottomConeLeft) -- (bottomConeRight);
            % Horizontal line at the middle of cone
            \draw[yellow, very thick](middleConeLeft) -- 
            node[black, above, yshift=-2pt]{$x$}(middleConeRight);
            % Horizontal line at the top of cone
            \draw[green, thick](topConeLeft) -- node[black, above]{$5(ft)$}(topConeRight);
            % Vertical line in middle of cone
            \draw[red,very thick](origin) -- (0, 6.025, 0);         
            % Adding the vertical lines with arrow tips
            \draw[customTip-customTip, blue, thick]
            ([xshift=1em]middleConeRight) -- node[black, above, fill=white, pos=0.65]{$y$}
            ([xshift=1em]middleConeRight|-bottomConeRight);
            %
            \draw[customTip-customTip, blue, thick]
            ([xshift=1em]topConeRight) -- node[black, above, fill=white, pos=0.55]{$10(ft)$}
            ([xshift=1em]topConeRight|-bottomConeRight);
        \end{axis}
    \end{tikzpicture}
\end{document}

相关内容