其他解决方法

其他解决方法

我刚刚尝试编译这个例子在我的 Windows 10 机器上,使用 MiKTeX 2.9,使用 TeX Maker 4.4.1

结果应该是这样的:

在此处输入图片描述

然而,编译的输出是不同的:

在此处输入图片描述

造成这种错误结果的根本原因是什么?...

更新 1:

即使替换.estyle.style,如上所述这里,输出仍然不是所需的数字:

在此处输入图片描述

更新 2:

@marsupilam 的主要答案仍然完全不起作用。作为角度 $\phi_{1}$ 和 $\phi_{2}$ 的参考的虚线没有被绘制(至少没有!):

在此处输入图片描述

答案1

TikZ 3.0.1a 中的键处理程序似乎已损坏(如果您使用、或任何等效键进行代码处理.estyle,则它会损坏)。解决方法是,将所有替换为(示例中出现两次)。.add style.prefix style.append style.estyle.style/.expanded

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
%% helper macros

% The 3D code is based on The drawing is based on Tomas M. Trzeciak's 
% `Stereographic and cylindrical map projections example`: 
% http://www.texample.net/tikz/examples/map-projections/
\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/.style/.expanded={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/.style/.expanded={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,thin,black] (\angVis:1) arc (\angVis:\angVis+180:1);
  \draw[current plane,thin,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}%this is fake: for drawing the grid
\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,red,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,red,thin] (\angVis:1) arc (\angVis:\angVis+180: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,thin,black] (\angVis:1) arc (\angVis:-\angVis-180:1);
  \draw[current plane,thin,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}%Defining functions to draw limited latitude circles (for the red mesh)
\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,red,thick] (-50:1) arc (-50:-35:1);

}

\tikzset{%
  >=latex,
  inner sep=0pt,%
  outer sep=2pt,%
  mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
    fill=black,circle}%
}
\usepackage{amsmath}
\usetikzlibrary{arrows}
\pagestyle{empty}
\usepackage{pgfplots}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}

\begin{document}
\begin{figure}[ht!]
    \begin{tikzpicture}[scale=1,every node/.style={minimum size=1cm}]
    %% some definitions

    \def\R{4} % 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=white!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+5.2376) coordinate (XEd);
    \path[pzplane] (\angBeta:\R) coordinate (P);%fino alla sfera
    \path[pzplane] (\angBeta:\R+5.2376) coordinate (Pd);%sfora di una quantità pari a 10 dopo la sfera
    \path[pzplane] (\angBeta:\R+5.2376) coordinate (Td);%sfora di una quantità pari a 10 dopo la sfera
    \path[pzplane] (\R,0) coordinate (PE);
    \path[pzplane] (\R+4,0) coordinate (PEd);
    \path[qzplane] (\angBeta:\R) coordinate (Q);
    \path[qzplane] (\angBeta:\R) coordinate (Qd);%sfora di una quantità pari a 10 dopo la sfera

    \path[qzplane] (\R,0) coordinate (QE);
    \path[qzplane] (\R+4,0) coordinate (QEd);%sfora di una quantità 10 dalla sfera sul piano equat.


    \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);
    \draw[dashed] (XE) -- (O) -- (PE);
    %draw black thick flat grid
    \draw[-,ultra thick,black] (Pd) -- (PEd) node[below, left] {$P_1$};%verticale sinistro
    \draw[-,ultra thick,black] (PEd) -- (QEd)node[below, right] {$P_3$};%orizzontale inferiore
    \draw[-,ultra thick,black] (Pd)-- (XEd)node[above, right] {$P_2$};%orizzontale superiore    
    \draw[-,ultra thick,black] (XEd) -- (QEd);  

    \draw[pzplane,->,thin] (0:0.5*\R) to[bend right=15]
        node[midway,right] {$\lambda$} (\angBeta:0.5*\R);
    \path[pzplane] (0.5*\angBeta:\R) node[right] {$$};
    \path[qzplane] (0.5*\angBeta:\R) node[right] {$$};
    \draw[equator,->,thin] (\angAz:0.5*\R) to[bend right=30]
        node[pos=0.4,above] {$\phi_1$} (\angPhiOne:0.5*\R);
    \draw[equator,->,thin] (\angAz:0.6*\R) to[bend right=35]
        node[midway,below] {$\phi_2$} (\angPhiTwo:0.6*\R);
            \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} }

    %labelling
    \draw[-latex,thick](4,-5.5)node[left]{$\mathsf{Grid(s)\ in\ Fig. \ (\ref{fig:Grid})}$}
                 to[out=0,in=270] (5.8,-2.3);
    \draw[thick](3.6,-6)node[left]{$[\mathsf{Rectilinear}]$};

\end{tikzpicture}
    \caption[Representation of spherical and regular computational grids used by SWAN]
    {Representation of spherical (red) and cartesian (black) co-ordinate systems. Latter 
    gives an example of unstructured grids. Both unstructured. Conversion from former 
    to latter involves a deformation factor which is acceptable within a given spatial limit. 
    For my case, only unstructured flat meshes are employed (\textit{Lisboa} Geodetic 
    datum: black grid on the right). Confront above represented points ($P_1,P_2,P_3$) with 
    Fig.(\ref{fig:Grid}). \\Mathematically frames change accordingly: see Eq.(\ref{eq:actbal2sph}).}
    \label{fig:frames}
\end{figure}



\end{document}

其他解决方法

您可以修补.estyle密钥处理程序:

\pgfkeys{/handlers/.estyle/.code=%
  \pgfkeys{\pgfkeyscurrentpath/.code/.expanded=\noexpand\pgfkeysalso{#1}}}

笔记

该漏洞已发现\pgfkeysedef并被引用为306号票

答案2

这似乎表面上在此修复该问题,但请参考 Paul Gaborit 的回答。

解释:

  1. 我注意到一些改变style修复estyle了某些东西但同时也破坏了其他东西。
  2. 因此,我只需定义两个版本的\LongitudePlane命令,一个带有estyle,一个带有style,并在需要时根据经验使用正确的版本。

代码 :

% Author: Marco Miani

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
%% helper macros

% The 3D code is based on The drawing is based on Tomas M. Trzeciak's 
% `Stereographic and cylindrical map projections example`: 
% http://www.texample.net/tikz/examples/map-projections/
\newcommand\pgfmathsinandcos[3]{%
  \pgfmathsetmacro#1{sin(#3)}%
  \pgfmathsetmacro#2{cos(#3)}%
}
\newcommand\LongitudePlaneE[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\LatitudePlaneE[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\LongitudePlane[3][current plane]{%
  \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  \pgfmathsinandcos\sint\cost{#3} % azimuth
  \tikzset{#1/.style={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/.style={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,thin,black] (\angVis:1) arc (\angVis:\angVis+180:1);
  \draw[current plane,thin,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}%this is fake: for drawing the grid
\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,red,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,red,thin] (\angVis:1) arc (\angVis:\angVis+180: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,thin,black] (\angVis:1) arc (\angVis:-\angVis-180:1);
  \draw[current plane,thin,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}%Defining functions to draw limited latitude circles (for the red mesh)
\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,red,thick] (-50:1) arc (-50:-35:1);

}

\tikzset{%
  >=latex,
  inner sep=0pt,%
  outer sep=2pt,%
  mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
    fill=black,circle}%
}
\usepackage{amsmath}
\usetikzlibrary{arrows}
\pagestyle{empty}
\usepackage{pgfplots}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}

\begin{document}
\begin{figure}[ht!]
    \begin{tikzpicture}[scale=1,every node/.style={minimum size=1cm}]
    %% some definitions

    \def\R{4} % 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
    \LongitudePlaneE[xzplane]{\angEl}{\angAz}
    \LongitudePlaneE[pzplane]{\angEl}{\angPhiOne}
    \LongitudePlaneE[qzplane]{\angEl}{\angPhiTwo}
    \LatitudePlane[equator]{\angEl}{0}
    \fill[ball color=white!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+5.2376) coordinate (XEd);
    \path[pzplane] (\angBeta:\R) coordinate (P);%fino alla sfera
    \path[pzplane] (\angBeta:\R+5.2376) coordinate (Pd);%sfora di una quantità pari a 10 dopo la sfera
    \path[pzplane] (\angBeta:\R+5.2376) coordinate (Td);%sfora di una quantità pari a 10 dopo la sfera
    \path[pzplane] (\R,0) coordinate (PE);
    \path[pzplane] (\R+4,0) coordinate (PEd);
    \path[qzplane] (\angBeta:\R) coordinate (Q);
    \path[qzplane] (\angBeta:\R) coordinate (Qd);%sfora di una quantità pari a 10 dopo la sfera

    \path[qzplane] (\R,0) coordinate (QE);
    \path[qzplane] (\R+4,0) coordinate (QEd);%sfora di una quantità 10 dalla sfera sul piano equat.


    \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);
    \draw[dashed] (XE) -- (O) -- (PE);
    %draw black thick flat grid
    \draw[-,ultra thick,black] (Pd) -- (PEd) node[below, left] {$P_1$};%verticale sinistro
    \draw[-,ultra thick,black] (PEd) -- (QEd)node[below, right] {$P_3$};%orizzontale inferiore
    \draw[-,ultra thick,black] (Pd)-- (XEd)node[above, right] {$P_2$};%orizzontale superiore    
    \draw[-,ultra thick,black] (XEd) -- (QEd);  

    \draw[pzplane,->,thin] (0:0.5*\R) to[bend right=15]
        node[midway,right] {$\lambda$} (\angBeta:0.5*\R);
    \path[pzplane] (0.5*\angBeta:\R) node[right] {$$};
    \path[qzplane] (0.5*\angBeta:\R) node[right] {$$};
    \draw[equator,->,thin] (\angAz:0.5*\R) to[bend right=30]
        node[pos=0.4,above] {$\phi_1$} (\angPhiOne:0.5*\R);
    \draw[equator,->,thin] (\angAz:0.6*\R) to[bend right=35]
        node[midway,below] {$\phi_2$} (\angPhiTwo:0.6*\R);
            \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} }

    %labelling
    \draw[-latex,thick](4,-5.5)node[left]{$\mathsf{Grid(s)\ in\ Fig. \ (\ref{fig:Grid})}$}
                 to[out=0,in=270] (5.8,-2.3);
    \draw[thick](3.6,-6)node[left]{$[\mathsf{Rectilinear}]$};

\end{tikzpicture}
    \caption[Representation of spherical and regular computational grids used by SWAN]
    {Representation of spherical (red) and cartesian (black) co-ordinate systems. Latter 
    gives an example of unstructured grids. Both unstructured. Conversion from former 
    to latter involves a deformation factor which is acceptable within a given spatial limit. 
    For my case, only unstructured flat meshes are employed (\textit{Lisboa} Geodetic 
    datum: black grid on the right). Confront above represented points ($P_1,P_2,P_3$) with 
    Fig.(\ref{fig:Grid}). \\Mathematically frames change accordingly: see Eq.(\ref{eq:actbal2sph}).}
    \label{fig:frames}
\end{figure}



\end{document} 

结果 结果

相关内容