Guest User

comment to https://tex.stackexchange.com/questions/199161/pa

a guest
Nov 12th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.67 KB | None | 0 0
  1. \documentclass[margin=5pt, tikz]{standalone}
  2. \usepackage{pgfplots}
  3. \usepackage{xxcolor}
  4. \pgfplotsset{compat=1.10}
  5.  
  6. % Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
  7. \pgfdeclareradialshading[tikz@ball]{ball}{\pgfqpoint{0bp}{0bp}}{%
  8.  color(0bp)=(tikz@ball!0!white);
  9.  color(7bp)=(tikz@ball!0!white);
  10.  color(15bp)=(tikz@ball!70!black);
  11.  color(20bp)=(black!70);
  12.  color(30bp)=(black!70)}
  13. \makeatother
  14.  
  15. % Style to set TikZ camera angle, like PGFPlots `view`
  16. \tikzset{viewport/.style 2 args={
  17.    x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
  18.    y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
  19.    z={(0,{cos(#2)*1cm})}
  20. }}
  21.  
  22. % Styles to plot only points that are before or behind the sphere.
  23. \pgfplotsset{only foreground/.style={
  24.    restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
  25. }}
  26. \pgfplotsset{only background/.style={
  27.    restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}
  28. }}
  29.  
  30. % Automatically plot transparent lines in background and solid lines in foreground
  31. \def\addFGBGplot[#1]#2;{
  32.    \addplot3[#1,only background, opacity=0.25] #2;
  33.    \addplot3[#1,only foreground] #2;
  34. }
  35.  
  36. \newcommand{\ViewAzimuth}{0}
  37. \newcommand{\ViewElevation}{30}
  38.  
  39. \begin{document}
  40. \begin{tikzpicture}
  41.     % Compute camera unit vector for calculating depth
  42.     \pgfmathsetmacro{\CameraX}{sin(\ViewAzimuth)*cos(\ViewElevation)}
  43.    \pgfmathsetmacro{\CameraY}{-cos(\ViewAzimuth)*cos(\ViewElevation)}
  44.    \pgfmathsetmacro{\CameraZ}{sin(\ViewElevation)}
  45.     \path[use as bounding box] (-1,-1) rectangle (1,1); % Avoid jittering animation
  46.     % Draw a nice looking sphere
  47.     \begin{scope}
  48.        \clip (0,0) circle (1);
  49.        \begin{scope}[transform canvas={rotate=-20}]
  50.            \shade [ball color=white] (0,0.5) ellipse (1.8 and 1.5);
  51.        \end{scope}
  52.    \end{scope}
  53.    \begin{axis}[
  54.        hide axis,
  55.        view={\ViewAzimuth}{\ViewElevation},     % Set view angle
  56.         every axis plot/.style={very thin},
  57.         disabledatascaling,                      % Align PGFPlots coordinates with TikZ
  58.         anchor=origin,                           % Align PGFPlots coordinates with TikZ
  59.         viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
  60.     ]
  61.          \foreach \i in {10,30,...,350} {
  62. \def\theX{0.5*(1-cos(deg(x)))} % 0 to 1 to 0
  63. \def\theY{0.5*(sin(deg(x))} % 0 to 0.5 to 0 to -0.5 to 0
  64.         \addFGBGplot[domain=0:2*pi, samples=101, samples y=1, red]
  65.         (
  66.             {sin(\i)*\theX}, % X coordinate
  67.             {sin(\i)*\theY}, % Y coordinate
  68.         {1-((1-cos(\i)))*\theX}
  69.        );
  70.        }
  71.    \end{axis}
  72. \end{tikzpicture}
  73. \end{document}
Add Comment
Please, Sign In to add comment