spherical-coordinates.tex 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. % Author: Marco Miani
  2. \documentclass[varwidth=true, border=2pt]{standalone}
  3. \usepackage{tikz}
  4. \usetikzlibrary{positioning}
  5. %% helper macros
  6. % The 3D code is based on The drawing is based on Tomas M. Trzeciak's
  7. % `Stereographic and cylindrical map projections example`:
  8. % http://www.texample.net/tikz/examples/map-projections/
  9. \newcommand\pgfmathsinandcos[3]{%
  10. \pgfmathsetmacro#1{sin(#3)}%
  11. \pgfmathsetmacro#2{cos(#3)}%
  12. }
  13. \newcommand\LongitudePlane[3][current plane]{%
  14. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  15. \pgfmathsinandcos\sint\cost{#3} % azimuth
  16. \tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
  17. }
  18. \newcommand\LatitudePlane[3][current plane]{%
  19. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  20. \pgfmathsinandcos\sint\cost{#3} % latitude
  21. \pgfmathsetmacro\yshift{\cosEl*\sint}
  22. \tikzset{#1/.estyle={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
  23. }
  24. \newcommand\DrawLongitudeCircle[2][1]{
  25. \LongitudePlane{\angEl}{#2}
  26. \tikzset{current plane/.prefix style={scale=#1}}
  27. % angle of "visibility"
  28. \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  29. \draw[current plane,thin,black] (\angVis:1) arc (\angVis:\angVis+180:1);
  30. \draw[current plane,thin,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
  31. }%this is fake: for drawing the grid
  32. \newcommand\DrawLongitudeCirclered[2][1]{
  33. \LongitudePlane{\angEl}{#2}
  34. \tikzset{current plane/.prefix style={scale=#1}}
  35. % angle of "visibility"
  36. \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  37. \draw[current plane,red,thick] (150:1) arc (150:180:1);
  38. }%for drawing the grid
  39. \newcommand\DLongredd[2][1]{
  40. \LongitudePlane{\angEl}{#2}
  41. \tikzset{current plane/.prefix style={scale=#1}}
  42. % angle of "visibility"
  43. \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  44. \draw[current plane,black,dashed, ultra thick] (150:1) arc (150:180:1);
  45. }
  46. \newcommand\DLatred[2][1]{
  47. \LatitudePlane{\angEl}{#2}
  48. \tikzset{current plane/.prefix style={scale=#1}}
  49. \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  50. % angle of "visibility"
  51. \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  52. \draw[current plane,dashed,black,ultra thick] (-50:1) arc (-50:-35:1);
  53. }
  54. \newcommand\fillred[2][1]{
  55. \LongitudePlane{\angEl}{#2}
  56. \tikzset{current plane/.prefix style={scale=#1}}
  57. % angle of "visibility"
  58. \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  59. \draw[current plane,red,thin] (\angVis:1) arc (\angVis:\angVis+180:1);
  60. }
  61. \newcommand\DrawLatitudeCircle[2][1]{
  62. \LatitudePlane{\angEl}{#2}
  63. \tikzset{current plane/.prefix style={scale=#1}}
  64. \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  65. % angle of "visibility"
  66. \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  67. \draw[current plane,thin,black] (\angVis:1) arc (\angVis:-\angVis-180:1);
  68. \draw[current plane,thin,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
  69. }%Defining functions to draw limited latitude circles (for the red mesh)
  70. \newcommand\DrawLatitudeCirclered[2][1]{
  71. \LatitudePlane{\angEl}{#2}
  72. \tikzset{current plane/.prefix style={scale=#1}}
  73. \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  74. % angle of "visibility"
  75. \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  76. %\draw[current plane,red,thick] (-\angVis-50:1) arc (-\angVis-50:-\angVis-20:1);
  77. \draw[current plane,red,thick] (-50:1) arc (-50:-35:1);
  78. }
  79. \tikzset{%
  80. >=latex,
  81. inner sep=0pt,%
  82. outer sep=2pt,%
  83. mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
  84. fill=black,circle}%
  85. }
  86. \usepackage{amsmath}
  87. \usetikzlibrary{arrows}
  88. \pagestyle{empty}
  89. \usepackage{pgfplots}
  90. \usetikzlibrary{calc,fadings,decorations.pathreplacing}
  91. \begin{document}
  92. \begin{tikzpicture}[scale=1,every node/.style={minimum size=1cm}]
  93. %% some definitions
  94. \def\R{4} % sphere radius
  95. \def\angEl{25} % elevation angle
  96. \def\angAz{-100} % azimuth angle
  97. \def\angPhiOne{-50} % longitude of point P
  98. \def\angPhiTwo{-35} % longitude of point Q
  99. \def\angBeta{30} % latitude of point P and Q
  100. %% working planes
  101. \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
  102. \LongitudePlane[xzplane]{\angEl}{\angAz}
  103. \LongitudePlane[pzplane]{\angEl}{\angPhiOne}
  104. \LongitudePlane[qzplane]{\angEl}{\angPhiTwo}
  105. \LatitudePlane[equator]{\angEl}{0}
  106. \fill[ball color=white!10] (0,0) circle (\R); % 3D lighting effect
  107. \coordinate (O) at (0,0);
  108. \coordinate[mark coordinate] (N) at (0,\H);
  109. \coordinate[mark coordinate] (S) at (0,-\H);
  110. \path[xzplane] (\R,0) coordinate (XE);
  111. %defining points outsided the area bounded by the sphere
  112. \path[qzplane] (\angBeta:\R+5.2376) coordinate (XEd);
  113. \path[pzplane] (\angBeta:\R) coordinate (P);%fino alla sfera
  114. \path[pzplane] (\angBeta:\R+5.2376) coordinate (Pd);%sfora di una quantità pari a 10 dopo la sfera
  115. \path[pzplane] (\angBeta:\R+5.2376) coordinate (Td);%sfora di una quantità pari a 10 dopo la sfera
  116. \path[pzplane] (\R,0) coordinate (PE);
  117. \path[pzplane] (\R+4,0) coordinate (PEd);
  118. \path[qzplane] (\angBeta:\R) coordinate (Q);
  119. \path[qzplane] (\angBeta:\R) coordinate (Qd);%sfora di una quantità pari a 10 dopo la sfera
  120. \path[qzplane] (\R,0) coordinate (QE);
  121. \path[qzplane] (\R+4,0) coordinate (QEd);%sfora di una quantità 10 dalla sfera sul piano equat.
  122. \DrawLongitudeCircle[\R]{\angPhiOne} % pzplane
  123. \DrawLongitudeCircle[\R]{\angPhiTwo} % qzplane
  124. \DrawLatitudeCircle[\R]{\angBeta}
  125. \DrawLatitudeCircle[\R]{0} % equator
  126. %labelling north and south
  127. \node[above=8pt] at (N) {$\mathbf{N}$};
  128. \node[below=8pt] at (S) {$\mathbf{S}$};
  129. \draw[-,dashed, thick] (N) -- (S);
  130. \draw[->] (O) -- (P);
  131. \draw[dashed] (XE) -- (O) -- (PE);
  132. \draw[dashed] (O) -- (QE);
  133. \draw[pzplane,->,thin] (0:0.5*\R) to[bend right=15]
  134. node[midway,right] {$v$} (\angBeta:0.5*\R);
  135. \path[pzplane] (0.5*\angBeta:\R) node[right] {$$};
  136. \path[qzplane] (0.5*\angBeta:\R) node[right] {$$};
  137. \draw[equator,->,thin] (\angAz:0.5*\R) to[bend right=30]
  138. node[pos=0.4,above] {$u$} (\angPhiOne:0.5*\R);
  139. \end{tikzpicture}
  140. \end{document}