球形弹性膜的微观结构

球形弹性膜的微观结构

我想在浅灰色不透明球体表面绘制一个 2D 网络。实际上,该网络代表由许多球和弹簧组成的 2D 方格,如下面 TikZ 代码中所示(由 @marmot 提供)。这个想法是让一个球形弹性膜捕获内部的理想气体。晶格本质上象征着膜的微观结构。

这个问题的根源在于:

在凸面上绘制二维方格(弹簧+球)

非常感谢您的帮助。

\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

这是第一次尝试:实心球体加上不同的绘图标记。其他一切都与最后一段代码相同这个答案

\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}

在此处输入图片描述

相关内容