答案1
你要求用 绘制某种东西pgfplots
。pgfplots
是一个不错的选择,因为它可以根据 3d 坐标为网格着色。 如下所示
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}[declare
function={rrr(\x,\y,\z)=sqrt(1+0.1*(\x*\x+\y*\y+\z*\z));}]
\begin{axis}[axis equal,
width=10cm,
height=10cm,
hide axis,
view={15}{8},
scale uniformly strategy=units only,
point meta={symbolic={0.1-0.08*y, % R
1-sqrt(x*x+y*y+z*z)/sqrt(4), % G
sqrt(x*x+y*y+z*z)/sqrt(4)%B
} },
domain = -1:1,
samples y=1,enlargelimits=0.2,
axis background/.style={fill=black}]
% this example burns colors if opacity
% is active in the document.
\fill[white] (0,0,0) circle[radius=0.1cm];
\foreach \X in {-1,-1/3,1/3,1}
{\foreach \Y in {-1,-1/3,1/3,1}
{\edef\temp{\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse]
({x*rrr(x,\X,\Y)}, {\X*rrr(x,\X,\Y)}, {\Y*rrr(x,\X,\Y)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse] ( {\X*rrr(x,\X,\Y)},{x*rrr(x,\X,\Y)},{\Y*rrr(x,\X,\Y)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse] ( {\X*rrr(x,\X,\Y)},{\Y*rrr(x,\X,\Y)},{x*rrr(x,\X,\Y)});
\noexpand\addplot3 [only marks,mark=ball,scatter,scatter src=1,
samples at={-1,-0.333,0.333,1},
mark options={ball color=white}] ( {\X*rrr(x,\X,\Y)},{x*rrr(x,\X,\Y)},{\Y*rrr(x,\X,\Y)});
}
\temp}}
\end{axis}
\end{tikzpicture}
\end{document}
但是,pgfplots
用透视图来绘制事物并不是一个好选择。对于这一点,这个perspective
库是一个更好的选择。所以如果你想要得到屏幕截图中的视图,我建议你问一个分离关于如何使用该perspective
库来绘制这个的问题。
尽管如此,您可以伪造透视,并使远处的图层“消失”。这是通过使(逆)“度量”rrr
依赖于 来实现的y
。(如果您打算使用rrr
:请注意,RGB 函数需要输入0
和之间的值1
。)
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}[declare
function={rrr(\x,\y,\z)=sqrt(1+0.1*(\x*\x+\y*\y+\z*\z))/(1+0.1*\y);}]
\begin{axis}[axis equal,
width=10cm,
height=10cm,
hide axis,
clip mode=individual,
view={8}{8},
scale uniformly strategy=units only,
point meta={symbolic={0.1-0.055*y, % R
1-sqrt(x*x+y*y+z*z)/sqrt(5), % G
sqrt(x*x+y*y+z*z)/sqrt(5)%B
} },
domain = -1:1,
samples y=1,enlargelimits=0.2,
axis background/.style={fill=black}]
% this example burns colors if opacity
% is active in the document.
%\clip (current axis.south west) rectangle (current axis.north west);
\foreach \Y in {1,0.333,-0.333,-1}
{\foreach \X in {-1,-0.333,0.333,1}
{\edef\temp{\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse]
({x*rrr(x,\Y,\X)},{\Y*rrr(x,\Y,\X)},{\X*rrr(x,\Y,\X)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse] ( {\X*rrr(x,\Y,\X)},{\Y*rrr(x,\Y,\X)},{x*rrr(x,\Y,\X)});
}
\temp}
\foreach \X in {-1,-0.333,0.333,1}
{\edef\temp{%
\noexpand\addplot3 [mark layer=like plot,only marks,mark=ball,scatter,scatter src=1,
samples at={-1,-0.333,0.333,1},mark options={ball color=white}]
({\X*rrr(\X,\Y,x)},{\Y*rrr(\X,\Y,x)},{x*rrr(\X,\Y,x)});
\ifdim\Y pt>-1pt
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,1)},
{x*rrr(\X,x,1)},{1*rrr(\X,x,1)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,0.333)},
{x*rrr(\X,x,0.333)},{0.333*rrr(\X,x,0.333)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,-0.333)},
{x*rrr(\X,x,-0.333)},{-0.333*rrr(\X,x,-0.333)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,-1)},
{x*rrr(\X,x,-1)},{-1*rrr(\X,x,-1)});
\noexpand\path[fill=black,fill opacity=0.1] (-1.2,\Y+0.667,-1.2) --
(1.2,\Y+0.667,-1.2) -- (1.2,\Y+0.667,1.2) -- (-1.2,\Y+0.667,1.2)
-- cycle;
\fi
}
\temp}}
\fill[white] (0,0,0) circle[radius=0.1cm];
\end{axis}
\end{tikzpicture}
\end{document}
或者中心有一个模糊的光源。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}[declare
function={rrr(\x,\y,\z)=sqrt(1+0.1*(\x*\x+\y*\y+\z*\z))/(1+0.1*\y);}]
\begin{axis}[axis equal,
width=10cm,
height=10cm,
hide axis,
clip mode=individual,
view={8}{8},
scale uniformly strategy=units only,
point meta={symbolic={0.1-0.055*y, % R
1-sqrt(x*x+y*y+z*z)/sqrt(5), % G
sqrt(x*x+y*y+z*z)/sqrt(5)%B
} },
domain = -1:1,
samples y=1,enlargelimits=0.2,
axis background/.style={fill=black}]
% this example burns colors if opacity
% is active in the document.
%\clip (current axis.south west) rectangle (current axis.north west);
\foreach \Y in {1,0.333,-0.333,-1}
{\foreach \X in {-1,-0.333,0.333,1}
{\edef\temp{\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse]
({x*rrr(x,\Y,\X)},{\Y*rrr(x,\Y,\X)},{\X*rrr(x,\Y,\X)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse] ( {\X*rrr(x,\Y,\X)},{\Y*rrr(x,\Y,\X)},{x*rrr(x,\Y,\X)});
}
\temp}
\foreach \X in {-1,-0.333,0.333,1}
{\edef\temp{%
\noexpand\addplot3 [mark layer=like plot,only marks,mark=ball,scatter,scatter src=1,
samples at={-1,-0.333,0.333,1},mark options={ball color=white}]
({\X*rrr(\X,\Y,x)},{\Y*rrr(\X,\Y,x)},{x*rrr(\X,\Y,x)});
\ifdim\Y pt>-1pt
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,1)},
{x*rrr(\X,x,1)},{1*rrr(\X,x,1)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,0.333)},
{x*rrr(\X,x,0.333)},{0.333*rrr(\X,x,0.333)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,-0.333)},
{x*rrr(\X,x,-0.333)},{-0.333*rrr(\X,x,-0.333)});
\noexpand\addplot3 [thick,patch, patch type=bilinear,
mesh/color input=explicit mathparse,domain=\Y-0.06:\Y-0.6667]
({\X*rrr(\X,x,-1)},
{x*rrr(\X,x,-1)},{-1*rrr(\X,x,-1)});
\noexpand\path[fill=black,fill opacity=0.1] (-1.2,\Y+0.667,-1.2) --
(1.2,\Y+0.667,-1.2) -- (1.2,\Y+0.667,1.2) -- (-1.2,\Y+0.667,1.2)
-- cycle;
\fi
}
\temp}}
\foreach \X in {0.9,0.8,...,0}
{\edef\temp{\noexpand\fill[white,opacity=1-\X,even odd rule]
(0,0,0) circle[radius=0.1cm+\X*0.04cm+0.004cm]
circle[radius=0.1cm+\X*0.04cm];}
\temp}
\fill[white] (0,0,0) circle[radius=0.1cm];
\end{axis}
\end{tikzpicture}
\end{document}