2

I have a problem when rendering the following code with MiKTeX (it renders fine with MacTeX). My arcs of longitude are not displaying correctly (pushed to the edges of the ball instead of towards the middle). I think the problem might be the PGF version I am using (3.0 on MiKTeX and 2.10 on MacTeX). Reading this post http://latex-community.org/forum/viewtopic.php?f=45&t=25293 it makes me wonder whether the problem is a bug in the PGF/TikZ version mention in this post, but it's been two years since this post. I've tried replacing .estyle by .style to no avail.

I have to get the code working with MiKTeX, is there any way to do that? I appreciate your advice!

\documentclass{article}
\usepackage{tikz}

\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\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[color=blue,current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
  \draw[color=blue,current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}

\begin{document}
\begin{tikzpicture}
    \def\R{2} % sphere radius
    \def\angEl{5} % elevation angle
    \def\meridian{-100}
    \fill[ball color=white!20] (0,0) circle (\R);
    \DrawLongitudeCircle[\R]{\meridian}
\end{tikzpicture}
\end{document}

Correctly rendered tikzpicture (with MacTeX)

Incorrectly rendered tikzpicture (with MiKTeX)

1 Answer 1

4

Replace .estyle by .style, as described in the post that you cite, resulting in the line

\tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}

The following image was typeset with the TeXLive 2016 distribution, tikz/pgf 2015/08/07 v3.0.1a. If the code below results in a different image, you maybe have to upgrade to the most recent version.

enter image description here

\documentclass{article}
\usepackage{tikz}

\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\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[color=blue,current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
  \draw[color=blue,current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}

\begin{document}
\begin{tikzpicture}
    \def\R{2} % sphere radius
    \def\angEl{5} % elevation angle
    \def\meridian{-100}
    \fill[ball color=white!20] (0,0) circle (\R);
    \DrawLongitudeCircle[\R]{\meridian}
\end{tikzpicture}
\end{document}
1
  • Thank you, gernot, it totally works. It is one of the first things I have tried, and I swear it wasn't working for me, next time I will not debug at 5am ;-) Thanks again, you are a champ!
    – Aina
    Dec 28, 2016 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.