1

I would like to draw a 2D network on the surface of a light-grey non-transparent sphere. In the actual fact, the network represents a 2D square lattice composed of many balls and springs as proposed below in TikZ code (by courtesy of @marmot). The idea is to have a spherical elastic membrane capturing an ideal gas inside. The lattice essentially symbolizes the microscopic structure of the membrane.

This question has its roots in the original one:

Drawing a 2D square lattice (springs + balls) on a convex surface

Thank you greatly for the help in advance.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\clip (-1,-1) rectangle (11,11);
\foreach \X in {-2,0,...,10}
{\foreach \Y in {-2,0,...,10}
 {\draw[decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}] (\X,\Y) -- ++(0,2) -- ++(2,0);
\node[circle,text=white,font=\sffamily\bfseries\large,inner
color=blue,outer color=black] at (\X,\Y) {+};}}
\end{tikzpicture}
\end{document}
  • 1
    Can you please add a sketch of what you want to achieve? – user121799 Dec 18 '18 at 11:52
  • The same as the picture from @marmot code (i.stack.imgur.com/Kz0Im.png), but spanned across the entire sphere which is coloured in non-transparent light-grey. – Savchenko Dec 18 '18 at 13:26
2

Here is a first attempt: solid sphere plus different plot marks. Everything else is as in the last code of this answer.

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{pgfplots}
\usepackage{xxcolor}
\pgfplotsset{compat=1.16}
\usetikzlibrary{decorations.pathmorphing,decorations.markings}
% 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;
}

% attempt to do similar things for discrete plots
\def\addFGBGSampleplot[#1]#2;{
    %\addplot3[#1,only background,gray!50] #2;
    \addplot3[#1,only foreground] #2;
}


\newcommand{\ViewAzimuth}{-30}
\newcommand{\ViewElevation}{30}

\tikzset{spring/.style={decorate,decoration={coil,aspect=0.5,amplitude=1.5mm, segment
length=1.5mm}}}
% pgfmanual p. 1087
\pgfdeclareradialshading{ballshading}{\pgfpoint{0bp}{0bp}}
 {color(0bp)=(blue!100!black); color(9bp)=(blue!90!black);
 color(18bp)=(blue!70!black); color(25bp)=(blue!50!black); color(50bp)=(black)}

\pgfdeclareplotmark{interesting}{\pgfpathcircle{\pgfpoint{0ex}{0ex}}{2ex}
  \pgfshadepath{ballshading}{0}
  \pgfusepath{}
  \pgfpathmoveto{\pgfpoint{0pt}{-5pt}}
  \pgfpathlineto{\pgfpoint{0pt}{5pt}}
  \pgfpathmoveto{\pgfpoint{-5pt}{0pt}}
  \pgfpathlineto{\pgfpoint{5pt}{0pt}}
  \pgfsetstrokecolor{white}
  \pgfsetlinewidth{0.8pt}
  \pgfusepath{stroke}
  }
\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)}
    \pgfmathsetmacro{\R}{12}
    \path[use as bounding box] (-\R,-\R) rectangle (\R,\R); % Avoid jittering animation
    % Draw a nice looking sphere
    \begin{scope}
        \clip (0,0) circle (\R);
        \begin{scope}[transform canvas={rotate=-20}]
            \shade [ball color=white] (0,0.5) ellipse (\R*1.8 and \R*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
    ]
        % plot latitude circles
        \pgfplotsinvokeforeach{-75,-45,...,75}
        {\addFGBGSampleplot[spring,domain=0:2*pi, samples=51, samples y=1]
        ({\R*cos(#1)*cos(deg(x))}, {\R*cos(#1)*sin(deg(x))}, {\R*sin(#1)});}
        % plot longitude circles
        \pgfplotsinvokeforeach{0,30,...,150}
        {\addFGBGSampleplot[spring,domain=0:2*pi, samples=51, samples y=1]
        ({\R*cos(#1)*cos(deg(x))}, {\R*sin(#1)*cos(deg(x))}, {\R*sin(deg(x))});     
        }
        % plot longitude circles
        \pgfplotsinvokeforeach{0,30,...,330}
        {\addFGBGSampleplot[only marks,mark=interesting,samples at={-75,-45,...,75}]
        ({\R*cos(#1)*cos(x)}, {\R*sin(#1)*cos(x)}, {\R*sin(x)});        
        }
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.