stereographic-projection.tex 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. % Source: http://www.texample.net/tikz/examples/map-projections/
  2. \documentclass[varwidth=true, border=2pt]{standalone}
  3. \usepackage{pgfplots}
  4. \usepackage{tikz}
  5. \usetikzlibrary{calc,fadings,decorations.pathreplacing}
  6. \begin{document}
  7. %% helper macros
  8. \begin{tikzpicture} % CENT
  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] (\angVis:1) arc (\angVis:\angVis+180:1);
  30. \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
  31. }
  32. \newcommand\DrawLatitudeCircle[2][1]{
  33. \LatitudePlane{\angEl}{#2}
  34. \tikzset{current plane/.prefix style={scale=#1}}
  35. \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  36. % angle of "visibility"
  37. \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  38. \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
  39. \draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
  40. }
  41. \tikzset{%
  42. >=latex, % option for nice arrows
  43. inner sep=0pt,%
  44. outer sep=2pt,%
  45. mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
  46. fill=black,circle}%
  47. }
  48. %% some definitions
  49. \def\R{2.5} % sphere radius
  50. \def\angEl{35} % elevation angle
  51. \def\angAz{-105} % azimuth angle
  52. \def\angPhi{-40} % longitude of point P
  53. \def\angBeta{19} % latitude of point P
  54. %% working planes
  55. \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
  56. \tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),
  57. cos(\angAz)*sin(\angEl),(0,-\H)}}}
  58. \LongitudePlane[xzplane]{\angEl}{\angAz}
  59. \LongitudePlane[pzplane]{\angEl}{\angPhi}
  60. \LatitudePlane[equator]{\angEl}{0}
  61. %% draw xyplane and sphere
  62. \draw[xyplane] (-2*\R,-2*\R) rectangle (2.2*\R,2.8*\R);
  63. \fill[ball color=white] (0,0) circle (\R); % 3D lighting effect
  64. \draw (0,0) circle (\R);
  65. %% characteristic points
  66. \coordinate (O) at (0,0);
  67. \coordinate[mark coordinate] (N) at (0,\H);
  68. \coordinate[mark coordinate] (S) at (0,-\H);
  69. \path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P);
  70. \path[pzplane] (\R,0) coordinate (PE);
  71. \path[xzplane] (\R,0) coordinate (XE);
  72. \path (PE) ++(0,-\H) coordinate (Paux); % to aid Phat calculation
  73. \coordinate[mark coordinate] (Phat) at (intersection cs: first line={(N)--(P)},
  74. second line={(S)--(Paux)});
  75. %% draw meridians and latitude circles
  76. \DrawLatitudeCircle[\R]{0} % equator
  77. \DrawLongitudeCircle[\R]{\angAz} % xzplane
  78. \DrawLongitudeCircle[\R]{\angAz+90} % yzplane
  79. \DrawLongitudeCircle[\R]{\angPhi} % pzplane
  80. %% draw xyz coordinate system
  81. \draw[xyplane,<->] (1.8*\R,0) node[below] {$x,\xi$} -- (0,0) -- (0,2.4*\R)
  82. node[right] {$y$};
  83. \draw[->] (0,-\H) -- (0,1.6*\R) node[above] {$z$};
  84. %% draw lines and put labels
  85. \draw[blue,dashed] (P) -- (N) +(0.3ex,0.6ex) node[above left,black] {$\mathbf{N}$};
  86. \draw[blue] (P) -- (Phat) node[above right,black] {$\mathbf{\hat{P}}$};
  87. \path (S) +(0.4ex,-0.4ex) node[below] {$\mathbf{0}$};
  88. \draw (P) node[above right] {$\mathbf{P}$};
  89. \end{tikzpicture}
  90. \end{document}