LaTeX forum ⇒ Graphics, Figures & Tables3d sphere old code

Information and discussion about graphics, figures & tables in LaTeX documents.
startrucky
Posts: 11
Joined: Mon Aug 18, 2014 2:02 pm

3d sphere old code

Postby startrucky » Mon Aug 18, 2014 3:25 pm

Hi there,
as recommended I moved here to make a new post rather than adding to an 6 year old one.
This one: http://latex-community.org/forum/viewtopic.php?f=4&t=2111&start=10
by the way, sorry I don't know how to link properly.

This is a crosspost to http://tex.stackexchange.com/questions/196902/3d-sphere-style-changes-coordinates

I got the problem that the code I modified is kinda old so... well I show you:
I want this:
want.jpg
What i want
want.jpg (118.66 KiB) Viewed 3989 times


which works in writeLatex, the problem is it uses estyle which leads to removed latitude and longitude circles using texniccenter and miktex:
screwed.jpg
without longitude circles
screwed.jpg (74.43 KiB) Viewed 3989 times


Replacing estyle by style, makes the lines appear again, but confused all the nodes:
screwed2.jpg
After change of estyle to style
screwed2.jpg (105.22 KiB) Viewed 3989 times


As far as I now this is a problem of the old code I am using, I would really appreciate some suggestions or somebody who knows the changes of tikz from i guess 1.5 to 3.0+

If somebody could tell me how to place my points again it should work.

Thanks and kind regards
sty

  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{calc,fadings,decorations.pathreplacing}
  4. \usepackage[active,tightpage]{preview}
  5. \PreviewEnvironment{tikzpicture}
  6. \setlength\PreviewBorder{5pt}
  7. \pagestyle{empty}
  8.  
  9. %% helper macros
  10. \newcommand\pgfmathsinandcos[3]{%
  11. \pgfmathsetmacro#1{sin(#3)}%
  12. \pgfmathsetmacro#2{cos(#3)}%
  13. }
  14. \newcommand\LongitudePlane[3][current plane]{%
  15. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  16. \pgfmathsinandcos\sint\cost{#3} % azimuth
  17. \tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
  18. }
  19. \newcommand\LatitudePlane[3][current plane]{%
  20. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  21. \pgfmathsinandcos\sint\cost{#3} % latitude
  22. \pgfmathsetmacro\yshift{\cosEl*\sint}
  23. \tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
  24. }
  25. \newcommand\DrawLongitudeCircle[2][1]{
  26. \LongitudePlane{\angEl}{#2}
  27. \tikzset{current plane/.prefix style={scale=#1}}
  28. % angle of "visibility"
  29. \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  30. \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
  31. \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
  32. }
  33. \newcommand\DrawLatitudeCircle[2][1]{
  34. \LatitudePlane{\angEl}{#2}
  35. \tikzset{current plane/.prefix style={scale=#1}}
  36. \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  37. % angle of "visibility"
  38. \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  39. \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
  40. \draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
  41. }
  42.  
  43. %% document-wide tikz options and styles
  44. \tikzset{%
  45. >=latex, % option for nice arrows
  46. inner sep=0pt,%
  47. outer sep=2pt,%
  48. mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,fill=black,circle}%
  49. }
  50.  
  51. \begin{document}
  52.  
  53. \begin{tikzpicture} % CENT
  54.  
  55. %% some definitions
  56. \def\R{4} % sphere radius
  57. \def\angEl{35} % elevation angle
  58. \def\angAz{-105} % azimuth angle
  59. \def\angPhi{-40} % longitude of point P
  60. \def\angBeta{25} % latitude of point P
  61.  
  62. %% working planes
  63. \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
  64. \tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),cos(\angAz)*sin(\angEl),(0,-\H)}}}
  65. \LongitudePlane[xzplane]{\angEl}{\angAz}
  66. \LongitudePlane[pzplane]{\angEl}{\angPhi}
  67. \LongitudePlane[yzplane]{\angEl}{\angAz+90}
  68. \LatitudePlane[equator]{\angEl}{0}
  69.  
  70. %% draw xyplane and sphere
  71. \fill[ball color=white] (0,0) circle (\R); % 3D lighting effect
  72. \draw (0,0) circle (\R);
  73.  
  74. \coordinate (O) at (0,0);
  75. \coordinate[mark coordinate] (N) at (0,\H);
  76. \coordinate[mark coordinate] (S) at (0,-\H);
  77. %\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P);
  78. \path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P1);
  79. \path[pzplane] (-\angBeta:\R) coordinate[mark coordinate] (P2);
  80. \path[pzplane] (\angBeta:2.2*\R) coordinate (P11);
  81. \path[pzplane] (-\angBeta:1.8*\R) coordinate (P22);
  82. \path[pzplane] (\angBeta:0.5*\R) coordinate (P15);
  83. \path[pzplane] (-\angBeta:0.5*\R) coordinate (P25);
  84.  
  85. %% draw meridians and latitude circles
  86. \DrawLatitudeCircle[\R]{0} % equator
  87. \DrawLongitudeCircle[\R]{\angAz} % xzplane
  88. \DrawLongitudeCircle[\R]{\angAz+90} % yzplane
  89. \DrawLongitudeCircle[\R]{\angPhi} % pzplane
  90.  
  91. %% draw xyz coordinate system
  92.  
  93. \draw[xzplane,->] (0,0) -- (1.9*\R,0) node[below] {$x$};
  94. \draw[yzplane,->] (0,0) -- (1.4*\R,0) node[below] {$y$};
  95. \draw[->] (0,0) -- (0,1.3*\R) node[above] {$z$};
  96. \draw[pzplane,->] (0,0) -- (1.5*\R,0) node[below] {$x_{2}$};
  97.  
  98. %% draw lines and put labels
  99. \draw[dashed] (S) -- (N) +(0.3ex,0.6ex) node[above left] {$\mathbf{N}$};
  100. \path (S) +(0.4ex,-0.4ex) node[below] {$\mathbf{S}$};
  101. \draw[dashed] (P11) -- (P1) -- (O) -- (P2) -- (P22);
  102. \draw[->,thin] (P22) to[bend right=25] node[pos=0.5,right] {$\beta$} (P11);
  103. \draw[equator,->,thin] (\angAz:0.5*\R) to[bend right=30] node[pos=0.44,below] {$\theta$} (\angPhi:0.5*\R);
  104.  
  105. \end{tikzpicture}
  106. \end{document}
Last edited by startrucky on Mon Aug 18, 2014 8:52 pm, edited 1 time in total.

Tags:

startrucky
Posts: 11
Joined: Mon Aug 18, 2014 2:02 pm

Postby startrucky » Mon Aug 18, 2014 8:38 pm

Here is a bloody fix up, by setting all points manually.
For the actual problem there seems to be a ticket http://sourceforge.net/p/pgf/bugs/306/

  1. \documentclass{article}
  2.  
  3. %%\usepackage[nomain,nonumberlist,acronym,section,description]{glossaries}
  4. %%\newglossary[alg]{acronymlist}{acr}{acn}{Abkverzeichnis}
  5. %%\makeglossaries
  6. %%
  7. %%\newacronym[description=Part of Speech test extra]{POS}{POS}{Part Of Speech}
  8. %%
  9. %%\begin{document}
  10. %%
  11. %%Test \gls{POS} and ?
  12. %%\glsaddall
  13. %%
  14. %%\printglossaries
  15. %%\input{globe}
  16. %% ========== glossaries test end
  17. %
  18. %\documentclass{article}
  19. %\usepackage{pgfplots}
  20. % added tikz-3dplots, 3D NOT CHANGING ANYTHING SO FAR
  21. \usepackage{tikz, tikz-3dplot}
  22. \usetikzlibrary{3D,calc,fadings,decorations.pathreplacing}
  23. \usepackage[active,tightpage]{preview}
  24. \PreviewEnvironment{tikzpicture}
  25. \setlength\PreviewBorder{5pt}
  26. \pagestyle{empty}
  27.  
  28. %% helper macros
  29. \newcommand{\pgfmathsinandcos}[3]{%
  30. \pgfmathsetmacro#1{sin(#3)}%
  31. \pgfmathsetmacro#2{cos(#3)}%
  32. }
  33. \newcommand{\LongitudePlane}[3][current plane]{%
  34. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  35. \pgfmathsinandcos\sint\cost{#3} % azimuth
  36. \tikzset{#1/.style={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
  37. }
  38. \newcommand{\LatitudePlane}[3][current plane]{%
  39. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  40. \pgfmathsinandcos\sint\cost{#3} % latitude
  41. \pgfmathsetmacro\yshift{\cosEl*\sint}
  42. \tikzset{#1/.style={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
  43. }
  44. \newcommand{\DrawLongitudeCircle}[2][1]{
  45. \LongitudePlane{\angEl}{#2}
  46. \tikzset{current plane/.prefix style={scale=#1}}
  47. % angle of "visibility"
  48. \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  49. \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
  50. \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
  51. }
  52. \newcommand{\DrawLatitudeCircle}[2][1]{
  53. \LatitudePlane{\angEl}{#2}
  54. \tikzset{current plane/.prefix style={scale=#1}}
  55. \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  56. % angle of "visibility"
  57. \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  58. \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
  59. \draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
  60. }
  61.  
  62. %% document-wide tikz options and styles
  63.  
  64. \tikzset{%
  65. >=latex, % option for nice arrows
  66. inner sep=0pt,%
  67. outer sep=2pt,%
  68. mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,fill=black,circle}%
  69. }
  70.  
  71. \begin{document}
  72.  
  73. \begin{tikzpicture} % CENT
  74.  
  75. %% some definitions
  76.  
  77. \def\R{4} % sphere radius
  78. \def\angEl{35} % elevation angle
  79. \def\angAz{-105} % azimuth angle
  80. \def\angPhi{-40} % longitude of point P
  81. \def\angBeta{25} % latitude of point P
  82.  
  83. %% working planes
  84.  
  85. \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
  86. \tikzset{xyplane/.style={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),cos(\angAz)*sin(\angEl),(0,-\H)}}}
  87. \LongitudePlane[xzplane]{\angEl}{\angAz}
  88. \LongitudePlane[pzplane]{\angEl}{\angPhi}
  89. \LongitudePlane[yzplane]{\angEl}{\angAz+90}
  90. \LatitudePlane[equator]{\angEl}{0}
  91.  
  92. %% draw xyplane and sphere
  93.  
  94. %\draw[xyplane] (-1.45*\R,-1.45*\R);% rectangle (2.2*\R,2.2*\R);
  95. %\draw[xyplane] (0.5*\R,1*\R); % rectangle (2.2*\R,2.2*\R);
  96. \fill[ball color=gray] (0,0) circle (\R); % 3D lighting effect
  97. %\fill[white] (0,0) circle (\R); % just a white circle
  98. \draw[gray] (0,0) circle (\R);
  99.  
  100. %% characteristic points
  101.  
  102. \coordinate (O) at (0,0);
  103. \coordinate[mark coordinate] (N) at (0,\H);
  104. \coordinate[mark coordinate] (S) at (0,-\H);
  105. %######################################################################
  106. % alternative to good style method
  107. \coordinate[mark coordinate] (P1) at (2.775,0.05); %good
  108. \coordinate (P11) at (6.1,0.115); %good
  109. \coordinate (pt15) at (1.39,0.02); %good
  110. \coordinate[mark coordinate] (P2) at (2.78,-2.725); %good
  111. \coordinate (P22) at (5,-4.9); %good
  112. \coordinate (P25) at (1.39,-1.36); %good
  113. %######################################################################
  114. %\path[pzplane] (\angEl:\R) coordinate[mark coordinate] (P);
  115. %\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P1);
  116. %\path[pzplane] (-\angBeta:\R) coordinate[mark coordinate] (P2);
  117. %\path[pzplane] (\angBeta:2.2*\R) coordinate (P11);
  118. %\path[pzplane] (-\angBeta:1.8*\R) coordinate (P22);
  119. %\path[pzplane] (\angBeta:0.5*\R) coordinate (P15);
  120. %\path[pzplane] (-\angBeta:0.5*\R) coordinate (P25);
  121. %\path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P1);
  122. %\path[pzplane] (-\angBeta:\R) coordinate[mark coordinate] (P2);
  123. %\path[pzplane] (\angBeta:2.2*\R) coordinate[mark coordinate] (P11);
  124. %\path[pzplane] (-\angBeta:1.8*\R) coordinate[mark coordinate] (P22);
  125. %\path[pzplane] (\angBeta:0.5*\R) coordinate[mark coordinate] (P15);
  126. %\path[pzplane] (-\angBeta:0.5*\R) coordinate[mark coordinate] (P25);
  127. %\path[pzplane] (\R,0) coordinate (PE);
  128. %\path[xzplane] (\R,0) coordinate (XE);
  129. %\path[xyplane] (\R,0) coordinate (XY)
  130. %\path (PE) ++(0,-\H) coordinate (Paux); % to aid Phat calculation
  131. %\coordinate[mark coordinate] (Phat) at (intersection cs: first line={(N)--(P)}, second line={(S)--(Paux)});
  132.  
  133. %% draw meridians and latitude circles
  134.  
  135. \DrawLatitudeCircle[\R,yellow]{0} % equator
  136. %%\DrawLatitudeCircle[\R]{\angBeta}
  137. \DrawLongitudeCircle[\R,blue]{\angAz} % xzplane
  138. \DrawLongitudeCircle[\R,green]{\angAz+90} % yzplane
  139. \DrawLongitudeCircle[\R,red]{\angPhi} % pzplane
  140.  
  141. %######################################################################
  142. % more alternative or workaround
  143. %\coordinate[mark coordinate,red] (x1) at (-1.95,-4.2);
  144. \coordinate (x1) at (-1.95,-4.2);
  145. \draw[->] (O)--(x1) node[below] {$x_{CIO}$};
  146. \coordinate (y1) at (5.45,-0.81);
  147. \draw[->] (O) -- (y1) node[below] {$y_{CIO}$};
  148. \coordinate (x2) at (4.6,-2.2);
  149. \draw[->] (O) -- (x2) node[below] {$x_{TIO}$};
  150. \coordinate (z1) at (0,5);
  151. \draw[->] (O) -- (z1) node[above] {$z_{CIP}$};
  152. %######################################################################
  153. %% draw xyz coordinate system
  154. %\draw[xyplane,<->] (1.5*\R,0) node[below] {$x$} -- (0,0) -- (0,1.5*\R) node[right] {$y$};
  155. %\draw[xzplane,->] (O) -- (1.9*\R,0) node[below] {$x_{CIO}$};
  156. %\draw[yzplane,->] (O) -- (1.4*\R,0) node[below] {$y_{CIO}$};
  157. %\draw[->] (O) -- (0,1.3*\R) node[above] {$z_{CIP}$};
  158. %\draw[pzplane,->] (O) -- (1.5*\R,0) node[below] {$x_{TIO}$};
  159.  
  160. %% draw lines and put labels
  161.  
  162. \draw[dashed] (S) -- (N) +(0.3ex,0.6ex) node[above left] {$\mathbf{N}$};
  163. %\draw (P) -- (Phat) node[above right] {$\mathbf{\hat{P}}$};
  164. \path (S) +(0.4ex,-0.4ex) node[below] {$\mathbf{S}$};
  165. %\draw[->] (O) -- (P) node[above right] {$\mathbf{P}$};
  166. \draw[dashed] (P11) -- (P1) -- (O) -- (P2) -- (P22);
  167. %\draw[pzplane,->,thin] (P15) to[bend right=15] node[pos=0.5,right] {$\beta_{CEO}$} (p25);
  168. %\draw[->,thin] (P25) to[bend right=15] node[pos=0.5,right] {$\beta_{CEO}$} (P15);
  169. \draw[->,thin] (P22) to[bend right=25] node[pos=0.5,right] {$\beta_{CEO}$} (P11);
  170. \draw[equator,->,thin,purple] (\angAz:0.5*\R) to[bend right=30] node[pos=0.44,below] {$\theta_{ERA}$} (\angPhi:0.5*\R);
  171. %\draw[thin,decorate,decoration={brace,raise=0.5pt,amplitude=1ex}] (N) -- (O) node[midway,right=1ex] {$a$};
  172.  
  173. \end{tikzpicture}
  174.  
  175. %\begin{tikzpicture}
  176. %\draw (-1,0) arc (180:360:1cm and 0.5cm);
  177. %\draw[dashed] (-1,0) arc (180:0:1cm and 0.5cm);
  178. %\draw (0,1) arc (90:270:0.5cm and 1cm);
  179. %\draw[dashed] (0,1) arc (90:-90:0.5cm and 1cm);
  180. %\draw (0,0) circle (1cm);
  181. %\draw (0,0) circle (0.008cm);
  182. %\shade[ball color=blue!10!white,opacity=0.20] (0,0) circle (1cm);
  183. %\end{tikzpicture}
  184.  
  185. \end{document}
  186.  

User avatar
cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Mon Aug 18, 2014 8:48 pm

This post looks like a crosspost to TeX.sx: http://tex.stackexchange.com/questions/ ... oordinates

It's always nice to give a link in such cases!

Regards
site moderator & package author

startrucky
Posts: 11
Joined: Mon Aug 18, 2014 2:02 pm

Postby startrucky » Mon Aug 18, 2014 8:53 pm

Yeah forgot that sorry, added it above as well just to make sure.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 9 guests