stereographic-projection.tex 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. %% helper macros
  2. \begin{tikzpicture} % CENT
  3. \newcommand\pgfmathsinandcos[3]{%
  4. \pgfmathsetmacro#1{sin(#3)}%
  5. \pgfmathsetmacro#2{cos(#3)}%
  6. }
  7. \newcommand\LongitudePlane[3][current plane]{%
  8. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  9. \pgfmathsinandcos\sint\cost{#3} % azimuth
  10. \tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
  11. }
  12. \newcommand\LatitudePlane[3][current plane]{%
  13. \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
  14. \pgfmathsinandcos\sint\cost{#3} % latitude
  15. \pgfmathsetmacro\yshift{\cosEl*\sint}
  16. \tikzset{#1/.estyle={cm={\cost,0,0,\cost*\sinEl,(0,\yshift)}}} %
  17. }
  18. \newcommand\DrawLongitudeCircle[2][1]{
  19. \LongitudePlane{\angEl}{#2}
  20. \tikzset{current plane/.prefix style={scale=#1}}
  21. % angle of "visibility"
  22. \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} %
  23. \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
  24. \draw[current plane,dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
  25. }
  26. \newcommand\DrawLatitudeCircle[2][1]{
  27. \LatitudePlane{\angEl}{#2}
  28. \tikzset{current plane/.prefix style={scale=#1}}
  29. \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}
  30. % angle of "visibility"
  31. \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
  32. \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
  33. \draw[current plane,dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
  34. }
  35. \tikzset{%
  36. >=latex, % option for nice arrows
  37. inner sep=0pt,%
  38. outer sep=2pt,%
  39. mark coordinate/.style={inner sep=0pt,outer sep=0pt,minimum size=3pt,
  40. fill=black,circle}%
  41. }
  42. %% some definitions
  43. \def\R{2.5} % sphere radius
  44. \def\angEl{35} % elevation angle
  45. \def\angAz{-105} % azimuth angle
  46. \def\angPhi{-40} % longitude of point P
  47. \def\angBeta{19} % latitude of point P
  48. %% working planes
  49. \pgfmathsetmacro\H{\R*cos(\angEl)} % distance to north pole
  50. \tikzset{xyplane/.estyle={cm={cos(\angAz),sin(\angAz)*sin(\angEl),-sin(\angAz),
  51. cos(\angAz)*sin(\angEl),(0,-\H)}}}
  52. \LongitudePlane[xzplane]{\angEl}{\angAz}
  53. \LongitudePlane[pzplane]{\angEl}{\angPhi}
  54. \LatitudePlane[equator]{\angEl}{0}
  55. %% draw xyplane and sphere
  56. \draw[xyplane] (-2*\R,-2*\R) rectangle (2.2*\R,2.8*\R);
  57. \fill[ball color=white] (0,0) circle (\R); % 3D lighting effect
  58. \draw (0,0) circle (\R);
  59. %% characteristic points
  60. \coordinate (O) at (0,0);
  61. \coordinate[mark coordinate] (N) at (0,\H);
  62. \coordinate[mark coordinate] (S) at (0,-\H);
  63. \path[pzplane] (\angBeta:\R) coordinate[mark coordinate] (P);
  64. \path[pzplane] (\R,0) coordinate (PE);
  65. \path[xzplane] (\R,0) coordinate (XE);
  66. \path (PE) ++(0,-\H) coordinate (Paux); % to aid Phat calculation
  67. \coordinate[mark coordinate] (Phat) at (intersection cs: first line={(N)--(P)},
  68. second line={(S)--(Paux)});
  69. %% draw meridians and latitude circles
  70. \DrawLatitudeCircle[\R]{0} % equator
  71. \DrawLongitudeCircle[\R]{\angAz} % xzplane
  72. \DrawLongitudeCircle[\R]{\angAz+90} % yzplane
  73. \DrawLongitudeCircle[\R]{\angPhi} % pzplane
  74. %% draw xyz coordinate system
  75. \draw[xyplane,<->] (1.8*\R,0) node[below] {$x$} -- (0,0) -- (0,2.4*\R)
  76. node[right] {$y$};
  77. \draw[->] (0,-\H) -- (0,1.6*\R) node[above] {$z$};
  78. %% draw lines and put labels
  79. \draw[blue,dashed] (P) -- (N) +(0.3ex,0.6ex) node[above left,black] {$\mathbf{N}$};
  80. \draw[blue] (P) -- (Phat) node[above right,black] {$\mathbf{\hat{P}}$};
  81. \path (S) +(0.4ex,-0.4ex) node[below] {$\mathbf{0}$};
  82. \draw (P) node[above right] {$\mathbf{P}$};
  83. \end{tikzpicture}