绘制表面和法向矢量场

绘制表面和法向矢量场

我想知道是否有一种简单的方法来绘制表面的网格图及其法线矢量场?

例如:我希望绘制球体 $x^2 + y^2 + z^2 = 1$,并且处的法向量场将是连接 (x,y,z) 和 (2x,2y,2z) 的所有向量,其中 (x,y,z) 位于球体上。tiks

答案1

这只是为了好玩,并建立在这个答案背景调查以及这个答案

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc}

\pgfplotsset{compute projections/.code=\pgfmathsetmacro{\CameraX}{sin(\pgfkeysvalueof{/pgfplots/view/az})*cos(\pgfkeysvalueof{/pgfplots/view/el})}
\pgfmathsetmacro{\CameraY}{-cos(\pgfkeysvalueof{/pgfplots/view/az})*cos(\pgfkeysvalueof{/pgfplots/view/el})}
\pgfmathsetmacro{\CameraZ}{sin(\pgfkeysvalueof{/pgfplots/view/el})},
only foreground/.style={compute projections,
    restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
},only background/.style={compute projections,
    restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}
}}
\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    domain=-1:1,
    samples=10,
    xmin=-1.5,xmax=1.5,
    ymin=-1.5,ymax=1.5,
    zmin=-1.5,zmax=1.5,
    ]
      \addplot3[,quiver,-stealth,only background,%opacity=0.1,
      domain=0:360,domain y=-90:90,point meta=1,
      quiver={
        u={x/sqrt((x)^2+(y)^2+(z)^2)},
        v={y/sqrt((x)^2+(y)^2+(z)^2)},
        w={z/sqrt((x)^2+(y)^2+(z)^2)},
        colored,scale arrows=0.5}]
      ({cos(y)*cos(x)},{-cos(y)*sin(x)},{sin(y)});
    %}
    \draw[ball color=gray] let \p1=($(0,0,1.75)-(0,0,0)$) in
     (0,0,0) circle[radius=\y1];
      \addplot3[quiver,-stealth,only foreground,%opacity=0.1,
      domain=0:360,domain y=-90:90,point meta=1,
      quiver={
        u={x/sqrt((x)^2+(y)^2+(z)^2)},
        v={y/sqrt((x)^2+(y)^2+(z)^2)},
        w={z/sqrt((x)^2+(y)^2+(z)^2)},
        colored,scale arrows=0.5}]
      ({cos(y)*cos(x)},{-cos(y)*sin(x)},{sin(y)});
  \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容