1

I have again a question about some 3D tikz problem. Added crosspost at: http://www.latex-community.org/forum/viewtopic.php?f=45&t=26046 Added german crosspost: http://texwelt.de/wissen/fragen/12291/3d-orbits-um-sphare-mit-koordinaten-oder-punkten-auf-umlaufbahn

The link to the overleaf (writelatex) section, I dont know if anybody can open it but here it is. https://www.overleaf.com/2433347sbhpck#/6330259/

Now to the actual problem:
The issue is the use of the path command referring to a former defined plane. The coordinates of the blue and black dots work on the blue and green track.
The orange dots are not on the plane they are supposed to, they should be on the red lines, where the O and o is, so please could someone help me find out what I am missing.

\documentclass{article} \usepackage{tikz, tikz-3dplot} \usetikzlibrary{calc,fadings,decorations.pathreplacing}

%% helper macros
\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{\OrbitPlane}[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[current plane] (\angVis:1) arc (\angVis:\angVis+180:1); 
  \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1); 
}
\newcommand{\DrawLatitudeCircle}[2][2]{
  \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{\DrawOrbitCircle}[2][3]{
  \OrbitPlane{\angEl-8}{#2} % orbit kippen!!!
  \tikzset{current plane/.prefix style={scale=#1}}
   % angle of "visibility" 
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  % original
    \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1); % sichtbarkeit des vor der kugel befindlichen bereichs
   \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1); 
   } % achtung unten auch eine winkeländerung !!!???

%% 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} 

%% some definitions 
\def\R{4} % sphere radius
\def\rr{5} % orbit radius?
\def\angEl{35} % elevation angle 
\def\angAz{-105} % azimuth angle 
\def\angPhi{-40} % longitude of point P 
\def\angBeta{25} % latitude of point P 

%######################################################################
%% working planes
\pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
\tikzset{xyplane/.style={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),cos(\angAz)*sin(\angEl),(0,-\H)}}}
\LongitudePlane[xzplane]{\angEl}{\angAz}
\LongitudePlane[pzplane]{\angEl}{\angPhi}
\LongitudePlane[yzplane]{\angEl}{\angAz+90}
\LatitudePlane[equator]{\angEl}{0}
\OrbitPlane[orbplanetwo]{\angEl-8}{\angAz} % dem orbit oben und unten winkel anpassen
\OrbitPlane[orbplane]{\angEl-8}{\angAz+60} % dem orbit oben und unten winkel anpassen

%######################################################################
%% draw xyplane and sphere
\fill[ball color=white!50!gray] (0,0) circle (\R); % 3D lighting effect
\draw[white] (0,0) circle (\R);

%% characteristic points
\path[orbplane] (\angBeta+10:\R/1) coordinate[mark coordinate,color=black] (P1); % works fine
\path[orbplane] (\angBeta+10:\rr/1) coordinate[mark coordinate,color=blue] (P2); % works fine

%#############################-problem-#########################################
\path[orbplanetwo] (\angPhi+50:\R/1) coordinate[mark coordinate,color=orange] (A1); % not at the expected position ???
\path[orbplanetwo] (\angBeta:\rr/1) coordinate[mark coordinate,color=orange] (A2); % not at the expected position ???

%##-wanted position of the orange dots-#####
\node at (-0.93,0) {o};
\node at (-1.15,0.05) {O};

%######################################################################
% Äquator, Orbit, Subspur etc.
%% draw meridians and latitude circles
\DrawLatitudeCircle[\R,yellow]{0} % equator
\DrawOrbitCircle[\rr,cyan]{\angAz+60} % orbit plane drehen !!!
\DrawOrbitCircle[\R,green]{\angAz+60} % orbit subspur !!!
\DrawOrbitCircle[\rr,red]{\angAz} % orbit plane drehen !!!
\DrawOrbitCircle[\R,red]{\angAz} % orbit subspur !!!

\end{tikzpicture} 
\end{document}

The Orange dots on the cyan and green line should be on the red lines, so how to achieve the right coordinates.

I would prefer to use the angles to set the coordinates, as I need them for some other stuff. Thanks for your help.

  • Thank you for marking it as a crosspost. This is exactly how it is supposed to be :-) – Johannes_B Mar 25 '15 at 9:39
  • Unfortunately, i cannot help you with TikZ. :-( – Johannes_B Mar 25 '15 at 9:40
  • Unfortunately nobody seems to use this a part from me, as the other questions I had didn't really get much response either. – startrucky Mar 26 '15 at 9:54
  • In one of your questions i saw comments in german, you might wanna check out TeXwelt.de, a german question and answer site. Don't forget to crosslink, though ;-) – Johannes_B Mar 26 '15 at 9:58
  • Right forgot that one thanks, as I mostly write my work in English I got used to search in English as well. – startrucky Mar 26 '15 at 10:01
1

The problem comes from the following line (in \OrbitPlane definition):

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

The \cost, \sint, \sinEl and \cosEl macros are not expanded before setting the style, so in your code both orbplane and orbplanetwo are set to the same style.# You should use the /.estyle key handler, giving you

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

This breaks the \DrawOrbitCircle with recent TikZ versions here:

\tikzset{current plane/.prefix style={scale=#1}}

since /.prefix handlers seems to have a bug when used after a /.estyle, to fix it:

\newcommand{\DrawOrbitCircle}[2][3]{
  \OrbitPlane{\angEl-8}{#2} % orbit kippen!!!
  % angle of "visibility" 
  \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  % original
  \draw[scale=#1,current plane] (\angVis:1) arc (\angVis:\angVis+180:1); % sichtbarkeit des vor der kugel befindlichen bereichs
  \draw[scale=#1,current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1); 
} % achtung unten auch eine winkeländerung !!!???
  • Awsome, thanks a lot, this seems to work, I still dont understand why the xz-yz-xy-planes dont work either, but probably that has to do with the change of estyle to style as well. It is great to know though that it is still possible to use estyle when scaling and deviding the radius by one as I figured out here:tex.stackexchange.com/questions/196902/… – startrucky Mar 26 '15 at 15:08

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.