向弯曲的网格区域添加法线矢量

向弯曲的网格区域添加法线矢量

我怎样才能将法线向量放在外面的蓝色网格上?

示例

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{amsmath}
\usetikzlibrary{arrows}
\usepackage{pgfplots}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}

\newcommand\pgfmathsinandcos[3]{%                                                  
  \pgfmathsetmacro#1{sin(#3)}%                                                     
  \pgfmathsetmacro#2{cos(#3)}%                                                     
}
\newcommand\LongitudePlane[3][current plane]{%                                     
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation                                    
  \pgfmathsinandcos\sint\cost{#3} % azimuth                                        
  \tikzset{#1/.estyle = {cm = {\cost, \sint*\sinEl, 0, \cosEl, (0,0)}}}            
}
\newcommand\LatitudePlane[3][current plane]{%                                      
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation                                    
  \pgfmathsinandcos\sint\cost{#3} % latitude                                       
  \pgfmathsetmacro\yshift{\cosEl*\sint}                                            
  \tikzset{#1/.estyle = {cm = {\cost, 0, 0, \cost*\sinEl, (0,\yshift)}}} %         
}
\newcommand\DrawLongitudeCircle[2][1]{                                             
  \LongitudePlane{\angEl}{#2}                                                      
  \tikzset{current plane/.prefix style = {scale = #1}}                             
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane] (\angVis:1) arc (\angVis:\angVis + 180:1);                  
  \draw[current plane, dashed] (\angVis - 180:1) arc (\angVis - 180:\angVis:1);    
}
\newcommand\DrawLatitudeCircle[2][1]{                                              
  \LatitudePlane{\angEl}{#2}                                                       
  \tikzset{current plane/.prefix style = {scale = #1}}                             
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}                            
  \draw[current plane] (\angVis:1) arc (\angVis:-\angVis - 180:1);                 
  \draw[current plane, dashed] (180 - \angVis:1) arc (180 - \angVis:\angVis:1);    
}
\newcommand\DrawLongitudeCirclered[2][1]{                                          
     \LongitudePlane{\angEl}{#2}                                                     
   \tikzset{current plane/.prefix style={scale=#1}}                                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane, blue, thick] (150:1) arc (150:180:1);                       
  % \draw[current plane,dashed] (-50:1) arc (-50:-35:1);                           
}%for drawing the grid                                                             
\newcommand\DLongredd[2][1]{                                                       
  \LongitudePlane{\angEl}{#2}                                                     
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane, black, dashed, ultra thick] (150:1) arc (150:180:1);        
}
\newcommand\DLatred[2][1]{                                                         
  \LatitudePlane{\angEl}{#2}                                                      
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}                            
  \draw[current plane, dashed, black, ultra thick] (-50:1) arc (-50:-35:1);        
}
\newcommand  \fillred[2][1]{                                                         
  \LongitudePlane{\angEl}{#2}                                                     
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane, blue, thin] (\angVis:1) arc (\angVis:\angVis+180:1);        
}
\newcommand\DrawLatitudeCirclered[2][1]{                                           
  \LatitudePlane{\angEl}{#2}                                                      
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}                            
% \draw[current plane,red,thick] (-\angVis-50:1) arc (-\angVis-50:-\angVis-20:1);  
  \draw[current plane, blue, thick] (-50:1) arc (-50:-35:1);                       
}


\tikzset{%                                                                        
  >=latex, % option for nice arrows                                               
  inner sep = 0pt,%                                                               
  outer sep = 2pt,%                                                               
  mark coordinate/.style = {inner sep = 0pt, outer sep = 0pt, minimum size = 3pt,
    fill = black, circle}%
}

\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\R{2} % sphere radius                                                      

\def\angEl{25} % elevation angle                                               
\def\angAz{-100} % azimuth angle                                               
\def\angPhiOne{-50} % longitude of point P                                     
\def\angPhiTwo{-35} % longitude of point Q                                     
\def\angBeta{30} % latitude of point P and Q                                   

%% working planes                                                              

\pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole                    
\LongitudePlane[xzplane]{\angEl}{\angAz}
\LongitudePlane[pzplane]{\angEl}{\angPhiOne}
\LongitudePlane[qzplane]{\angEl}{\angPhiTwo}
\LatitudePlane[equator]{\angEl}{0}
\fill[ball color = green!10] (0,0) circle (\R); % 3D lighting effect           
\coordinate (O) at (0,0);
\coordinate[mark coordinate] (N) at (0,\H);
\coordinate[mark coordinate] (S) at (0,-\H);
\path[xzplane] (\R,0) coordinate (XE);
 %defining points outsided the area bounded by the sphere                       
\path[qzplane] (\angBeta:\R+3) coordinate (XEd);
\path[pzplane] (\angBeta:\R) coordinate (P);
\path[pzplane] (\angBeta:\R+3) coordinate (Pd);
\path[pzplane] (\angBeta:\R+5.2376) coordinate (Td);
\path[pzplane] (\R,0) coordinate (PE);
\path[pzplane] (\R+3,0) coordinate (PEd);
\path[qzplane] (\angBeta:\R) coordinate (Q);
\path[qzplane] (\angBeta:\R) coordinate (Qd);

\path[qzplane] (\R,0) coordinate (QE);
\path[qzplane] (\R+3,0) coordinate (QEd);


\DrawLongitudeCircle[\R]{\angPhiOne} % pzplane                                 
\DrawLongitudeCircle[\R]{\angPhiTwo} % qzplane                                 
\DrawLatitudeCircle[\R]{\angBeta}
\DrawLatitudeCircle[\R]{0} % equator                                           
% labelling north and south                                                    
\node[above = 8pt] at (N) {$\mathbf{N}$};
\node[below = 8pt] at (S) {$\mathbf{S}$};

\draw[-, dashed, thick] (N) -- (S);
%\draw[->] (O) -- (P);                                                         
%\draw[dashed] (XE) -- (O) -- (PE);                                            
\draw[dashed] (O) -- (QE);
% connecting Points outside the sphere                                         
\draw[-, dashed, black, very thick] (O) -- (Pd);
\draw[-, dashed, black, very thick] (O) -- (PEd);
\draw[-, dashed, black, very thick] (O) -- (QEd);
\draw[-, dashed, black, very thick] (O) -- (XEd);
\path[pzplane] (0.5*\angBeta:\R) node[right] {$$};
\path[qzplane] (0.5*\angBeta:\R) node[right] {$$};
\path[xzplane] (0:\R) node[below] {$$};
\path[xzplane] (\angBeta:\R) node[below left] {$$};
\foreach \t in {0,2,...,30} { \DrawLatitudeCirclered[\R]{\t} }
\foreach \t in {130,133,...,145} { \DrawLongitudeCirclered[\R]{\t} }

% drawing grids on the spere invoking DLongredd and DrawLongitudeCirclered     

\foreach \t in {130,145,...,145} { \DLongredd[\R+3]{\t} }
\foreach \t in {130,133,...,145} { \DrawLongitudeCirclered[\R+3]{\t} }

\foreach \t in {0,30,...,30} { \DLatred[\R+3]{\t} }
\foreach \t in {0,2,...,30} { \DrawLatitudeCirclered[\R+3]{\t} }
\end{tikzpicture}
\caption{The normal pressure force of the surrounding water on $m$.}
\end{figure}

\end{document}

答案1

我使用不太最小的 MWE 中已定义的原语创建了一个解决方案。:-)

在此处输入图片描述

新增内容

由于代码较长,我将逐行解释我的添加内容;完整的代码如下。

\def\angPhiAvg{-42.5}
定义矢量要跟随的角度 phi(在本例中为网格范围的平均值)。

\LongitudePlane[myplane]{\angEl}{\angPhiAvg}
定义矢量所在的附加工作平面。

\path[myplane] (\angBeta/2:\R+3) coordinate (Ts);
\path[myplane] (\angBeta/2:\R+4) coordinate (Tf);
定义向量的开始和结束;在本例中为单位长度。

\draw[->, green, very thick] (Ts) -- (Tf) node[right] {$\mathbf{\hat{n}}$};
绘制并标记法线矢量。

完整代码

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{amsmath}
\usetikzlibrary{arrows}
\usepackage{pgfplots}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}

\newcommand\pgfmathsinandcos[3]{%                                                  
  \pgfmathsetmacro#1{sin(#3)}%                                                     
  \pgfmathsetmacro#2{cos(#3)}%                                                     
}
\newcommand\LongitudePlane[3][current plane]{%                                     
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation                                    
  \pgfmathsinandcos\sint\cost{#3} % azimuth                                        
  \tikzset{#1/.estyle = {cm = {\cost, \sint*\sinEl, 0, \cosEl, (0,0)}}}            
}
\newcommand\LatitudePlane[3][current plane]{%                                      
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation                                    
  \pgfmathsinandcos\sint\cost{#3} % latitude                                       
  \pgfmathsetmacro\yshift{\cosEl*\sint}                                            
  \tikzset{#1/.estyle = {cm = {\cost, 0, 0, \cost*\sinEl, (0,\yshift)}}} %         
}
\newcommand\DrawLongitudeCircle[2][1]{                                             
  \LongitudePlane{\angEl}{#2}                                                      
  \tikzset{current plane/.prefix style = {scale = #1}}                             
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane] (\angVis:1) arc (\angVis:\angVis + 180:1);                  
  \draw[current plane, dashed] (\angVis - 180:1) arc (\angVis - 180:\angVis:1);    
}
\newcommand\DrawLatitudeCircle[2][1]{                                              
  \LatitudePlane{\angEl}{#2}                                                       
  \tikzset{current plane/.prefix style = {scale = #1}}                             
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}                            
  \draw[current plane] (\angVis:1) arc (\angVis:-\angVis - 180:1);                 
  \draw[current plane, dashed] (180 - \angVis:1) arc (180 - \angVis:\angVis:1);    
}
\newcommand\DrawLongitudeCirclered[2][1]{                                          
     \LongitudePlane{\angEl}{#2}                                                     
   \tikzset{current plane/.prefix style={scale=#1}}                                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane, blue, thick] (150:1) arc (150:180:1);                       
  % \draw[current plane,dashed] (-50:1) arc (-50:-35:1);                           
}%for drawing the grid                                                             
\newcommand\DLongredd[2][1]{                                                       
  \LongitudePlane{\angEl}{#2}                                                     
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane, black, dashed, ultra thick] (150:1) arc (150:180:1);        
}
\newcommand\DLatred[2][1]{                                                         
  \LatitudePlane{\angEl}{#2}                                                      
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}                            
  \draw[current plane, dashed, black, ultra thick] (-50:1) arc (-50:-35:1);        
}
\newcommand  \fillred[2][1]{                                                         
  \LongitudePlane{\angEl}{#2}                                                     
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %                 
  \draw[current plane, blue, thin] (\angVis:1) arc (\angVis:\angVis+180:1);        
}
\newcommand\DrawLatitudeCirclered[2][1]{                                           
  \LatitudePlane{\angEl}{#2}                                                      
  \tikzset{current plane/.prefix style={scale=#1}}                                 
  \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}                 
  % angle of "visibility"                                                          
  \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}                            
% \draw[current plane,red,thick] (-\angVis-50:1) arc (-\angVis-50:-\angVis-20:1);  
  \draw[current plane, blue, thick] (-50:1) arc (-50:-35:1);                       
}


\tikzset{%                                                                        
  >=latex, % option for nice arrows                                               
  inner sep = 0pt,%                                                               
  outer sep = 2pt,%                                                               
  mark coordinate/.style = {inner sep = 0pt, outer sep = 0pt, minimum size = 3pt,
    fill = black, circle}%
}

\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\def\R{2} % sphere radius                                                      

\def\angEl{25} % elevation angle                                               
\def\angAz{-100} % azimuth angle                                               
\def\angPhiOne{-50} % longitude of point P                                     
\def\angPhiTwo{-35} % longitude of point Q                       
\def\angPhiAvg{-42.5} % longitude of normal vector ******              
\def\angBeta{30} % latitude of point P and Q                                   

%% working planes                                                              

\pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole                    
\LongitudePlane[xzplane]{\angEl}{\angAz}
\LongitudePlane[pzplane]{\angEl}{\angPhiOne}
\LongitudePlane[qzplane]{\angEl}{\angPhiTwo}
\LongitudePlane[myplane]{\angEl}{\angPhiAvg} % ******
\LatitudePlane[equator]{\angEl}{0}
\fill[ball color = green!10] (0,0) circle (\R); % 3D lighting effect           
\coordinate (O) at (0,0);
\coordinate[mark coordinate] (N) at (0,\H);
\coordinate[mark coordinate] (S) at (0,-\H);
\path[xzplane] (\R,0) coordinate (XE);
 %defining points outsided the area bounded by the sphere                       
\path[qzplane] (\angBeta:\R+3) coordinate (XEd);
\path[pzplane] (\angBeta:\R) coordinate (P);
\path[pzplane] (\angBeta:\R+3) coordinate (Pd);
\path[myplane] (\angBeta/2:\R+3) coordinate (Ts); % ******
\path[myplane] (\angBeta/2:\R+4) coordinate (Tf); % ******
\path[pzplane] (\R,0) coordinate (PE);
\path[pzplane] (\R+3,0) coordinate (PEd);
\path[qzplane] (\angBeta:\R) coordinate (Q);
\path[qzplane] (\angBeta:\R) coordinate (Qd);

\path[qzplane] (\R,0) coordinate (QE);
\path[qzplane] (\R+3,0) coordinate (QEd);


\DrawLongitudeCircle[\R]{\angPhiOne} % pzplane                                 
\DrawLongitudeCircle[\R]{\angPhiTwo} % qzplane                                 
\DrawLatitudeCircle[\R]{\angBeta}
\DrawLatitudeCircle[\R]{0} % equator                                           
% labelling north and south                                                    
\node[above = 8pt] at (N) {$\mathbf{N}$};
\node[below = 8pt] at (S) {$\mathbf{S}$};

\draw[-, dashed, thick] (N) -- (S);
%\draw[->] (O) -- (P);                                                         
%\draw[dashed] (XE) -- (O) -- (PE);                                            
\draw[dashed] (O) -- (QE);
% connecting Points outside the sphere                                         
\draw[-, dashed, black, very thick] (O) -- (Pd);
\draw[-, dashed, black, very thick] (O) -- (PEd);
\draw[-, dashed, black, very thick] (O) -- (QEd);
\draw[-, dashed, black, very thick] (O) -- (XEd);
\path[pzplane] (0.5*\angBeta:\R) node[right] {$$};
\path[qzplane] (0.5*\angBeta:\R) node[right] {$$};
\path[xzplane] (0:\R) node[below] {$$};
\path[xzplane] (\angBeta:\R) node[below left] {$$};
\foreach \t in {0,2,...,30} { \DrawLatitudeCirclered[\R]{\t} }
\foreach \t in {130,133,...,145} { \DrawLongitudeCirclered[\R]{\t} }
\draw[->, green, very thick] (Ts) -- (Tf) node[right] {$\mathbf{\hat{n}}$}; % ******

% drawing grids on the spere invoking DLongredd and DrawLongitudeCirclered     

\foreach \t in {130,145,...,145} { \DLongredd[\R+3]{\t} }
\foreach \t in {130,133,...,145} { \DrawLongitudeCirclered[\R+3]{\t} }

\foreach \t in {0,30,...,30} { \DLatred[\R+3]{\t} }
\foreach \t in {0,2,...,30} { \DrawLatitudeCirclered[\R+3]{\t} }
\end{tikzpicture}
\caption{The normal pressure force of the surrounding water on $m$.}
\end{figure}

\end{document}

相关内容