下列的这个问题关于黑洞的表现,一个人怎样才能表现一个tikzduck
或一个tikzmarmot
被它吞噬的存在。
在此过程中,任何动物或生物都不应受到伤害。
我认为此解决方案基于非线性变换或这个使用transform canvas
可能会有帮助,但我真的不知道从哪里开始。
\documentclass[border=3.14pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis line style={draw=none},
tick style={draw=none},
colormap/Blues,
data cs=polar,
samples=50,
domain=0:360,
y domain=1:10,
declare function={darkhole(\r)={-exp(-\r)};
% added functions to calculate cartesian coordinates from polar coordinates
pol2cartX(\angle,\radius) = \radius * cos(\angle);
pol2cartY(\angle,\radius) = \radius * sin(\angle);
},
xtick={\empty},
ytick={\empty},
ztick={\empty},
]
\addplot3 [surf,shader=flat,draw=black,z buffer=sort] {darkhole(y)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
只有当黑洞是虫洞时,土拨鼠才会掉进去。除此之外,你需要分两部分绘制黑洞,首先是背景,然后是乘客,然后是前景。
\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{compat=1.16}
\usepackage{tikzmarmots}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\blackholetransformation{%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
\pgfmathsetmacro{\myy}{\pgf@ya-40*exp(-0.04*abs(\the\pgf@xa))}%
\pgf@y=\myy pt}
\makeatother
\newsavebox\Back
\newsavebox\Front
\sbox\Back{\begin{tikzpicture}
\begin{axis}[
axis line style={draw=none},
tick style={draw=none},
colormap/Blues,
data cs=polar,
samples=25,
y domain=1:10,
declare function={darkhole(\r)={exp(-1)-exp(-\r)};
% added functions to calculate cartesian coordinates from polar coordinates
pol2cartX(\angle,\radius) = \radius * cos(\angle);
pol2cartY(\angle,\radius) = \radius * sin(\angle);
},
xtick={\empty},
ytick={\empty},
ztick={\empty},
]
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{-darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{-darkhole(y)};
\end{axis}
\end{tikzpicture}}
\sbox\Front{\begin{tikzpicture}
\begin{axis}[
axis line style={draw=none},
tick style={draw=none},
colormap/Blues,
data cs=polar,
samples=25,
y domain=1:10,
declare function={darkhole(\r)={exp(-1)-exp(-\r)};
% added functions to calculate cartesian coordinates from polar coordinates
pol2cartX(\angle,\radius) = \radius * cos(\angle);
pol2cartY(\angle,\radius) = \radius * sin(\angle);
},
xtick={\empty},
ytick={\empty},
ztick={\empty},
]
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{-darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{-darkhole(y)};
\end{axis}
\end{tikzpicture}}
\begin{document}
\foreach \X in {-50,-48,...,-8,8,10,...,50}%{-50,-40,...,50}%
{\begin{tikzpicture}
\begin{scope}[local bounding box=nonlinear,transform shape
nonlinear=true]
\pgftransformnonlinear{\blackholetransformation}
\path[use as bounding box] (-5,-4) rectangle (5,5);
\node[scale=2]{\usebox\Back};
\begin{scope}[xshift={-1cm+\X*1mm},yshift={-1*tanh(\X/10)*4cm-1cm}]
\marmot
\end{scope}
\node[scale=2]{\usebox\Front};
\end{scope}
\end{tikzpicture}}
\end{document}
另一个版本坠落速度较慢。
\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{compat=1.16}
\usepackage{tikzmarmots}
\usepgfmodule{nonlineartransformations}
\makeatletter
\def\blackholetransformation{%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
\pgfmathsetmacro{\myy}{\pgf@ya-60*exp(-0.06*abs(\the\pgf@xa))}%
\pgf@y=\myy pt}
\makeatother
\newsavebox\Back
\newsavebox\Front
\sbox\Back{\begin{tikzpicture}
\begin{axis}[
axis line style={draw=none},
tick style={draw=none},
colormap/Blues,
data cs=polar,
samples=25,
y domain=1:10,
declare function={darkhole(\r)={exp(-1)-exp(-\r)};
% added functions to calculate cartesian coordinates from polar coordinates
pol2cartX(\angle,\radius) = \radius * cos(\angle);
pol2cartY(\angle,\radius) = \radius * sin(\angle);
},
xtick={\empty},
ytick={\empty},
ztick={\empty},
]
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{-darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{-darkhole(y)};
\end{axis}
\end{tikzpicture}}
\sbox\Front{\begin{tikzpicture}
\begin{axis}[
axis line style={draw=none},
tick style={draw=none},
colormap/Blues,
data cs=polar,
samples=25,
y domain=1:10,
declare function={darkhole(\r)={exp(-1)-exp(-\r)};
% added functions to calculate cartesian coordinates from polar coordinates
pol2cartX(\angle,\radius) = \radius * cos(\angle);
pol2cartY(\angle,\radius) = \radius * sin(\angle);
},
xtick={\empty},
ytick={\empty},
ztick={\empty},
]
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,opacity=0,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}+180]
{-darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{darkhole(y)};
\addplot3[surf,shader=flat,draw=black,z buffer=sort,
domain=\pgfkeysvalueof{/pgfplots/view/az}:\pgfkeysvalueof{/pgfplots/view/az}-180]
{-darkhole(y)};
\end{axis}
\end{tikzpicture}}
\begin{document}
\foreach \X in {-50,-48,...,50}
{\begin{tikzpicture}[declare function={darkhole(\r)=exp(-2.5)-exp(-\r);}]
\path[use as bounding box] (-5,-6) rectangle (5,7);
\node[scale=2]{\usebox\Back};
\begin{scope}
\clip (-5,6) -- plot[domain=-5:-0.5] ({\x},{25*darkhole(abs(5*\x))})
-- plot[domain=-0.5:-5] ({\x},{-25*darkhole(abs(5*\x))})
|- (5,-7)
-- plot[domain=5:0.5] ({\x},{-25*darkhole(abs(5*\x))})
-- plot[domain=0.5:5] ({\x},{25*darkhole(abs(5*\x))}) |-cycle;
\begin{scope}[local bounding box=nonlinear,transform shape
nonlinear=true]
\pgftransformnonlinear{\blackholetransformation}
\begin{scope}[xshift={-1cm+\X*1mm},yshift={-1*tanh(\X/10)*4cm-1cm}]
\marmot
\end{scope}
\end{scope}
\end{scope}
\node[scale=2]{\usebox\Front};
\end{tikzpicture}}
\end{document}