TikZ 图表的问题

TikZ 图表的问题

这是我的问题,我定义了此代码中的所有命令以便具有一种透视并将圆圈视为在 3d 空间中(虚线部分位于后面)。我的问题是,如果我改变仰角,圆圈也不会发生任何事情。有人能看到我犯的任何错误吗?

\documentclass{standalone}

\usepackage{amsmath,amsfonts,amssymb,amscd,amsthm,xspace}
\usepackage[centerlast,small,sc]{caption}
\usepackage{epstopdf}
\usepackage{graphicx}
\usepackage{float}
\usepackage{epstopdf}
\usepackage{rotating}
\usepackage{tikz-cd}
\usepackage{tikz}
 \usetikzlibrary{decorations.pathmorphing,calc,shapes,positioning,fit,arrows,fadings,decorations.pathreplacing}
\usetikzlibrary{decorations.markings}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{textcomp}
\usepackage{enumerate}
\usepackage{verbatim}

\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);
}

%% document-wide tikz options and styles

\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{tikzpicture}[rotate=90]
  \def\R{0.5}
  \def\angEl{-30}
  \foreach \t in {0} { \DrawLatitudeCircle[\R]{\t} }
  %\draw[dashed] (0,.5) arc (0:180: .5 and .25);
  %\draw (0,.5) arc (180:360: .5 and .25);
  \draw (-1,-3) ellipse (.5 and .25);
  \draw (1,-3) ellipse (.5 and .25);
  \draw (-.5,0) to[out=-90,in=90] (-1.5,-3);
  \draw (.5,0) to[out=-90,in=90] (1.5,-3);
  \draw (-.5,-3) to[out=90,in=180] (0,-2);
  \draw (0,-2) to[out=0,in=90] (.5,-3);
\end{tikzpicture}

\end{document}

这在我的电脑上产生了以下结果,

在此处输入图片描述

笔记可能是我包含的软件包比必要的多,因为所有这些都是更大文档的一部分。我在 Mac 上使用 TeX 发行版 2014。我之所以这么说,是因为我最近在从 2013 版更新到 2014 版后重新编译了这个文件,而在更新之前一切都运行良好。

答案1

这不是你犯的错误。你的代码的问题在于它使用了estyle(内部使用\edef)语法。很可能你是在一段时间前获得的代码,当时estyle有不同的实现。要恢复所需的行为,只需在和的定义中更改estyle为:style\LongitudePlane\LatitudePlane

\documentclass{standalone}

\usepackage{amsmath,amsfonts,amssymb,amscd,amsthm,xspace}
\usepackage[centerlast,small,sc]{caption}
\usepackage{epstopdf}
\usepackage{graphicx}
\usepackage{float}
\usepackage{epstopdf}
\usepackage{rotating}
\usepackage{tikz-cd}
\usepackage{tikz}
 \usetikzlibrary{decorations.pathmorphing,calc,shapes,positioning,fit,arrows,fadings,decorations.pathreplacing}
\usetikzlibrary{decorations.markings}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{textcomp}
\usepackage{enumerate}
\usepackage{verbatim}

\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={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] (\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);
}

%% document-wide tikz options and styles

\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{tikzpicture}[rotate=90]
  \def\R{0.5}
  \def\angEl{-30}
  \foreach \t in {0} { \DrawLatitudeCircle[\R]{\t} }
  %\draw[dashed] (0,.5) arc (0:180: .5 and .25);
  %\draw (0,.5) arc (180:360: .5 and .25);
  \draw (-1,-3) ellipse (.5 and .25);
  \draw (1,-3) ellipse (.5 and .25);
  \draw (-.5,0) to[out=-90,in=90] (-1.5,-3);
  \draw (.5,0) to[out=-90,in=90] (1.5,-3);
  \draw (-.5,-3) to[out=90,in=180] (0,-2);
  \draw (0,-2) to[out=0,in=90] (.5,-3);
\end{tikzpicture}

\end{document}

在此处输入图片描述

顺便说一句,使用只有一次迭代的循环似乎有点过头了。

\foreach \t in {0} { \DrawLatitudeCircle[\R]{\t} }

你可以简单地说

\DrawLatitudeCircle[\R]{0}

答案2

您已经收到了 Andrew Stacey 通过 percusse 发送的有关图书馆的消息tqft。以下是示例。

\documentclass{article}
\usepackage{tikz}
    \usetikzlibrary{tqft}
\begin{document}
\begin{tikzpicture}[tqft/cobordism/.style={draw},tqft/every lower boundary component/.style={draw,dashed}, every tqft/.append style={transform shape } ]
  \begin{scope}[rotate=90]
    \pic [tqft/pair of pants];
  \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容