Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass[margin=5pt, tikz]{standalone}
- \usepackage{pgfplots}
- \usepackage{xxcolor}
- \pgfplotsset{compat=1.10}
- % Declare nice sphere shading: http://tex.stackexchange.com/a/54239/12440
- \pgfdeclareradialshading[tikz@ball]{ball}{\pgfqpoint{0bp}{0bp}}{%
- color(0bp)=(tikz@ball!0!white);
- color(7bp)=(tikz@ball!0!white);
- color(15bp)=(tikz@ball!70!black);
- color(20bp)=(black!70);
- color(30bp)=(black!70)}
- \makeatother
- % Style to set TikZ camera angle, like PGFPlots `view`
- \tikzset{viewport/.style 2 args={
- x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
- y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
- z={(0,{cos(#2)*1cm})}
- }}
- % Styles to plot only points that are before or behind the sphere.
- \pgfplotsset{only foreground/.style={
- restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-0.05:100},
- }}
- \pgfplotsset{only background/.style={
- restrict expr to domain={rawx*\CameraX + rawy*\CameraY + rawz*\CameraZ}{-100:0.05}
- }}
- % Automatically plot transparent lines in background and solid lines in foreground
- \def\addFGBGplot[#1]#2;{
- \addplot3[#1,only background, opacity=0.25] #2;
- \addplot3[#1,only foreground] #2;
- }
- \newcommand{\ViewAzimuth}{0}
- \newcommand{\ViewElevation}{30}
- \begin{document}
- \begin{tikzpicture}
- % Compute camera unit vector for calculating depth
- \pgfmathsetmacro{\CameraX}{sin(\ViewAzimuth)*cos(\ViewElevation)}
- \pgfmathsetmacro{\CameraY}{-cos(\ViewAzimuth)*cos(\ViewElevation)}
- \pgfmathsetmacro{\CameraZ}{sin(\ViewElevation)}
- \path[use as bounding box] (-1,-1) rectangle (1,1); % Avoid jittering animation
- % Draw a nice looking sphere
- \begin{scope}
- \clip (0,0) circle (1);
- \begin{scope}[transform canvas={rotate=-20}]
- \shade [ball color=white] (0,0.5) ellipse (1.8 and 1.5);
- \end{scope}
- \end{scope}
- \begin{axis}[
- hide axis,
- view={\ViewAzimuth}{\ViewElevation}, % Set view angle
- every axis plot/.style={very thin},
- disabledatascaling, % Align PGFPlots coordinates with TikZ
- anchor=origin, % Align PGFPlots coordinates with TikZ
- viewport={\ViewAzimuth}{\ViewElevation}, % Align PGFPlots coordinates with TikZ
- ]
- \foreach \i in {10,30,...,350} {
- \def\theX{0.5*(1-cos(deg(x)))} % 0 to 1 to 0
- \def\theY{0.5*(sin(deg(x))} % 0 to 0.5 to 0 to -0.5 to 0
- \addFGBGplot[domain=0:2*pi, samples=101, samples y=1, red]
- (
- {sin(\i)*\theX}, % X coordinate
- {sin(\i)*\theY}, % Y coordinate
- {1-((1-cos(\i)))*\theX}
- );
- }
- \end{axis}
- \end{tikzpicture}
- \end{document}
Add Comment
Please, Sign In to add comment