如何绘制切线及其在 xy 平面上的投影

如何绘制切线及其在 xy 平面上的投影

如何绘制切线及其在 xy 平面上的投影。我想实际重现如下所示的表面。 在此处输入图片描述 请修改我的代码:

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{shadings}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
    \begin{tikzpicture}[bullet/.style={circle,fill,inner sep=1pt},
        declare function={f(\x,\y)=2-.8*pow(\x-1.25,3)-0.8*pow(\y-1,3);}]
        \begin{axis}[view={125}{30},colormap/blackwhite,axis lines=middle,%
            zmax=2.2,zmin=0,xmin=0,xmax=2.4,ymin=0,ymax=2,%
            xlabel=$x$,ylabel=$y$,zlabel=$z$,
            xtick=\empty,ytick=\empty,ztick=\empty]
            %surface 
            \addplot3[surf,shader=interp,domain=0.6:2,domain y=0.5:1.2,opacity=0.4] {f(x,y)};
            %curve on surface
            \addplot3[thick,domain=0.4:1.2,samples y=1]  ({x+.6},{1.5*x},{f(x+.6,1.5*x)}); 
            \draw[dashed] (1,0,0) node[above left]{$x_0$} -- (1.1,1.2,0) node[bullet] (b1) {}  -- (0,1.2,0) node[above right]{$y_0$} (1.1,1.2,0) -- (1.1,1.2,{f(1,1.2)-.42})node[bullet] {};
                \addplot3[surf,shader=interp,domain=0.6:2,domain y=1.2:1.9,opacity=0.4] {f(x,y)};
                \draw (1,1,{f(1,1.2)}) -- (1,0.2,{f(1,1.2)+0.2}) coordinate[pos=0.5] (aux2);
        \end{axis}
    \end{tikzpicture}
\end{document}

答案1

在此处输入图片描述

我稍微修改了您的代码,并添加了控制点和曲线的常量以及函数的偏导数。这样您就可以一致地定义切向量;它(\ux,\uy,\uz)在下面的代码中。

不要忘记,图形元素的顺序很重要。

代码

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{math, arrows.meta}
\usetikzlibrary{shadings}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}

\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=1pt},
  declare function={%
    f(\x,\y)=2-.8*pow(\x-1.25,3)-0.8*pow(\y-1,3);
    fx(\x,\y)=-.8*3*pow(\x-1.25,2);
    fy(\x,\y)=-.8*3*pow(\y-1,2);
  },
  evaluate={%
    real \a, \b, \ux, \uy, \uz, \t;
    \ux = 1;
    \uy = 1.5;
    \t = .8;
    \a = \ux*\t +.6;
    \b = \uy*\t;
    \uz = fx(\a,\b)*\ux +fy(\a,\b)*\uy;
  }]
  \begin{axis}[%
    view={125}{30},
    colormap/blackwhite,
    axis lines=middle,
    zmax=2.2, zmin=0,
    xmin=0, xmax=2.4,
    ymin=0, ymax=2,
    xlabel=$x$, ylabel=$y$, zlabel=$z$,
    xtick=\empty, ytick=\empty, ztick=\empty]
    % point
    \draw[blue, dashed] (\a,0,0) node[below] {$x_0$}
    -- (\a,\b,0) node[bullet] (pxy) {}
    -- (0,\b,0) node[below] {$y_0$};
    \draw[blue, dashed] (pxy.center)
    -- (\a,\b,{f(\a,\b)}) node (p) {};
    % surface 
    \addplot3[%
    surf,
    shader=interp,
    domain=0.6:2,
    domain y=0.5:1.9,
    opacity=0.3] {f(x,y)};
    
    % curve on surface
    \addplot3[
    thick,
    domain=0.4:1.2,
    samples y=1]  ({\ux*x+.6}, {\uy*x}, {f(\ux*x+.6,\uy*x)});

    % curve projection
    \addplot3[
    thick,
    domain=0.4:1.2,
    samples y=1]  ({x+.6}, {1.5*x}, 0);

    \draw[blue] (p) node[bullet] {};

    %tangent vector
    \draw[blue, very thick, -Latex] (p.center)
    -- ++(\ux,\uy,\uz) coordinate[pos=0.5] (aux2);
  \end{axis}
\end{tikzpicture}
\end{document}

相关内容