如何在 TiKz 中从表面绘制圆形投影?

如何在 TiKz 中从表面绘制圆形投影?

我想要复制下图。

在此处输入图片描述

我不想使用 addplot3 并尝试了以下方法

\begin{tikzpicture}[font=\sffamily,declare function={%
    f(\x,\y)=3+0.075*cos(\x*100)*cos(\y*100)-0.035*(\y-5)^2-0.01*(\x-5)^2; % f(x,y) = 3 + 0.075*cos(x*100)*cos(y*100) - 0.035*(y-5)^2 - 0.01*(x-5)^2

    \tdplotsetmaincoords{70}{110}

    \begin{scope}[tdplot_main_coords]

        \draw[-latex] (0,0,0) -- (8,0,0) node[anchor=north] {$x$};
        \draw[-latex] (0,0,0) -- (0,8,0) node[anchor=west] {$y$};
        \draw[-latex] (0,0,0) -- (0,0,4) node[anchor=south] {$z$};

        % draw 2 x Grid       
        \foreach \a in {3,...,7}
        {
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\a},{\b},0);
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\b},{\a},0);
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\a},{\b},{f(\a,\b)});
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\b},{\a},{f(\b,\a)});
        }


        \fill[black,name path=x0] (5,5,0) circle (1pt) node[anchor=north] {\footnotesize $x_0$};

        
        \coordinate (x0) at (5,5,0);
        \draw[densely dashed,red,name path=circle_2D] (x0) circle (1);
        
        \coordinate (z0) at (5,5,{f(5,5)});
        \coordinate (z1) at (4,5,{f(4,5)});
        \coordinate (z2) at (5,6,{f(5,6)});
        \coordinate (z3) at (6,5,{f(6,5)});
        \coordinate (z4) at (4,5,{f(4,5)});
        
    \end{scope}
\end{tikzpicture}

使用 XeLatex 编译

在此处输入图片描述

但我无法在表面上画圆,有人能帮我吗?提前谢谢了。

答案1

您可以借助f定义表面的函数来实现。投影圆的参数方程为

x=5+cos(x),
y=5+sin(x),

函数 f 将给出z坐标

z=f(x,y)=f(5+cos(x),5+sin(x))

因此,完整的代码可能是:

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[font=\sffamily,declare function={%
    f(\x,\y)=3+0.075*cos(\x*100)*cos(\y*100)-0.035*(\y-5)^2-0.01*(\x-5)^2; % f(x,y) = 3 + 0.075*cos(x*100)*cos(y*100) - 0.035*(y-5)^2 - 0.01*(x-5)^2
    g(\x) = 0.075*(\x-4)^2+4;
    h(\x) = 0.02*(\x-4)^3-.2*(\x-4)+4;
    t(\x,\y)=f(4,4)-0.05*(\x-4) 0.02*(\y-4);}]

    \tdplotsetmaincoords{70}{110}

    \begin{scope}[tdplot_main_coords]
        \draw[-latex] (0,0,0) -- (8,0,0) node[anchor=north] {$x$};
        \draw[-latex] (0,0,0) -- (0,8,0) node[anchor=west] {$y$};
        \draw[-latex] (0,0,0) -- (0,0,4) node[anchor=south] {$z$};

        % draw 2 x Grid       
        \foreach \a in {3,...,7}
        {
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\a},{\b},0);
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\b},{\a},0);
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\a},{\b},{f(\a,\b)});
            \draw[thin,gray] plot[variable=\b,samples=60,smooth,domain=3:7] ({\b},{\a},{f(\b,\a)});
        }
        % Circle on the surface
        \draw[red] plot[samples=60,smooth,domain=0:360] ({5+cos(\x)},{5+sin(\x)},{f(5+cos(\x),5+sin(\x)});
        % Points
        \fill[black,name path=x0] (5,5,0) circle (1pt) node[anchor=north] {\footnotesize $x_0$};

        % \node[circle,fill=myorange,minimum size=6pt,inner sep=0pt] (P) at (2,2){}; 
        
        \coordinate (x0) at (5,5,0);
        \draw[densely dashed,red,name path=circle_2D] (x0) circle (1);
        
        % \fill[red] (5,5,{f(5,5)}) circle (1pt) node[anchor=north east] {};
        \coordinate (z0) at (5,5,{f(5,5)});
        \coordinate (z1) at (4,5,{f(4,5)});
        \coordinate (z2) at (5,6,{f(5,6)});
        \coordinate (z3) at (6,5,{f(6,5)});
        \coordinate (z4) at (4,5,{f(4,5)});
        
    \end{scope}
\end{tikzpicture}
\end{document}

输出结果如下: 在此处输入图片描述

编辑:正如评论中所建议的,我正在向表面添加一些填充。“圆圈”很容易,但网格需要关闭四个plots。

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{70}{110}

\tikzset{my plot/.style={samples=61,smooth}}

\begin{document}
\begin{tikzpicture}[font=\sffamily,tdplot_main_coords,declare function={%
    f(\x,\y)=3+0.075*cos(\x*100)*cos(\y*100)-0.035*(\y-5)^2-0.01*(\x-5)^2;}]
    % axes
    \draw[-latex] (0,0,0) -- (8,0,0) node[anchor=north] {$x$};
    \draw[-latex] (0,0,0) -- (0,8,0) node[anchor=west]  {$y$};
    \draw[-latex] (0,0,0) -- (0,0,4) node[anchor=south] {$z$};
    % grids   
    \foreach \a in {3,...,7}
    {
       \draw[thin,gray] plot[my plot,variable=\b,domain=3:7] ({\a},{\b},0);
       \draw[thin,gray] plot[my plot,variable=\b,domain=3:7] ({\b},{\a},0);
       \draw[thin,gray] plot[my plot,variable=\b,domain=3:7] ({\a},{\b},{f(\a,\b)});
       \draw[thin,gray] plot[my plot,variable=\b,domain=3:7] ({\b},{\a},{f(\b,\a)});
    }
    \fill[gray,fill opacity=0.2] plot[my plot,variable=\b,domain=3:7] (3,{\b},{f(3,\b)}) -- 
                                 plot[my plot,variable=\a,domain=3:7] ({\a},7,{f(\a,7)}) --
                                 plot[my plot,variable=\b,domain=7:3] (7,{\b},{f(7,\b)}) --
                                 plot[my plot,variable=\a,domain=7:3] ({\a},3,{f(\a,3)});
    % Circle on the surface
    \draw[red,fill=red,fill opacity=0.2] plot[my plot,domain=0:360] ({5+cos(\x)},{5+sin(\x)},{f(5+cos(\x),5+sin(\x)});
    % Point and other circle
    \coordinate (x0) at (5,5,0);
    \fill (x0) circle (1pt) node[anchor=north] {\footnotesize $x_0$};
    \draw[densely dashed,red] (x0) circle (1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容