感谢@marmot,我绘制了如下所示的球壳片段。是否有可能在 TikZ 代码中用颜色填充片段的表面(包括不透明度、渐变等)?提前感谢您的帮助。
\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.pathmorphing,calc}
\makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
\define@key{x sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{x sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{x sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
\setkeys{x sphericalkeys}{#1}%
\pgfpointxyz{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}}
%along y axis
\define@key{y sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{y sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{y sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
\setkeys{y sphericalkeys}{#1}%
\pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*sin(\myphi)}}
%along z axis
\define@key{z sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{z sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{z sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
\setkeys{z sphericalkeys}{#1}%
\pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}{\myradius*cos(\mytheta)}}
\makeatother % https://tex.stackexchange.com/a/438695/121799
\begin{document}
\tdplotsetmaincoords{80}{70}
\begin{tikzpicture}[tdplot_main_coords]
\pgfmathsetmacro{\R}{6}
\pgfmathsetmacro{\RR}{5.5}
\pgfmathsetmacro{\RRRR}{7.5}
\pgfmathsetmacro{\RRR}{15}
\path[clip]
plot[variable=\x,domain=25:95]
(z spherical cs:radius=\RRRR,theta=80+5,phi=\x)
-- plot[variable=\x,domain=25:95]
(z spherical cs:radius=\RRRR,theta=80-\x,phi=95)
-- plot[variable=\x,domain=95:25]
(z spherical cs:radius=\RRRR,theta=80-65,phi=\x)
-- plot[variable=\x,domain=95:25]
(z spherical cs:radius=\RRRR,theta=80-\x,phi=-25);
\draw[line width=0.275mm,dashed] plot[variable=\x,domain=5:30](z spherical cs:radius=\RR,theta=55-\x,phi=55);
\draw[line width=0.275mm] plot[variable=\x,domain=5:30](z spherical cs:radius=\RR,theta=55-\x,phi=5);
\draw[line width=0.275mm] plot[variable=\x,domain=5:55](z spherical cs:radius=\RR,theta=50,phi=\x);
\draw[line width=0.275mm,dashed] plot[variable=\x,domain=5:55](z spherical cs:radius=\RR,theta=25,phi=\x);
\draw[line width=0.275mm] plot[variable=\x,domain=5:30](z spherical cs:radius=\R,theta=55-\x,phi=55);
\draw[line width=0.275mm] plot[variable=\x,domain=5:30](z spherical cs:radius=\R,theta=55-\x,phi=5);
\draw[line width=0.275mm] plot[variable=\x,domain=5:55](z spherical cs:radius=\R,theta=50,phi=\x);
\draw[line width=0.275mm] plot[variable=\x,domain=5:55](z spherical cs:radius=\R,theta=25,phi=\x);
\draw[line width=0.275mm] plot[variable=\x,domain=\R:\RR](z spherical cs:radius=\x,theta=50,phi=55);
\draw[line width=0.275mm] plot[variable=\x,domain=\R:\RR](z spherical cs:radius=\x,theta=50,phi=5);
\draw[line width=0.275mm] plot[variable=\x,domain=\R:\RR](z spherical cs:radius=\x,theta=25,phi=5);
\draw[line width=0.275mm,dashed] plot[variable=\x,domain=\R:\RR](z spherical cs:radius=\x,theta=25,phi=55);
\end{tikzpicture}
\end{document}
答案1
您一开始就已经将多个图合并到一条路径中clip
。对面执行相同操作可让您为它们添加阴影。
\documentclass[tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.pathmorphing,calc}
\makeatletter
%from https://tex.stackexchange.com/a/375604/121799
%along x axis
\define@key{x sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{x sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{x sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{x spherical}{% %%%rotation around x
\setkeys{x sphericalkeys}{#1}%
\pgfpointxyz{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}}
%along y axis
\define@key{y sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{y sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{y sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{y spherical}{% %%%rotation around x
\setkeys{y sphericalkeys}{#1}%
\pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*cos(\mytheta)}{\myradius*sin(\mytheta)*sin(\myphi)}}
%along z axis
\define@key{z sphericalkeys}{radius}{\def\myradius{#1}}
\define@key{z sphericalkeys}{theta}{\def\mytheta{#1}}
\define@key{z sphericalkeys}{phi}{\def\myphi{#1}}
\tikzdeclarecoordinatesystem{z spherical}{% %%%rotation around x
\setkeys{z sphericalkeys}{#1}%
\pgfpointxyz{\myradius*sin(\mytheta)*cos(\myphi)}{\myradius*sin(\mytheta)*sin(\myphi)}{\myradius*cos(\mytheta)}}
\makeatother % https://tex.stackexchange.com/a/438695/121799
\begin{document}
\tdplotsetmaincoords{80}{70}
\begin{tikzpicture}[tdplot_main_coords,line join=bevel]
\pgfmathsetmacro{\R}{6}
\pgfmathsetmacro{\RR}{5.5}
\pgfmathsetmacro{\RRRR}{7.5}
\pgfmathsetmacro{\RRR}{15}
\path[clip]
plot[variable=\x,domain=25:95]
(z spherical cs:radius=\RRRR,theta=80+5,phi=\x)
-- plot[variable=\x,domain=25:95]
(z spherical cs:radius=\RRRR,theta=80-\x,phi=95)
-- plot[variable=\x,domain=95:25]
(z spherical cs:radius=\RRRR,theta=80-65,phi=\x)
-- plot[variable=\x,domain=95:25]
(z spherical cs:radius=\RRRR,theta=80-\x,phi=-25);
\draw[line width=0.275mm,dashed] plot[variable=\x,domain=5:30](z spherical cs:radius=\RR,theta=55-\x,phi=55);
\draw[line width=0.275mm,dashed] plot[variable=\x,domain=5:55](z spherical cs:radius=\RR,theta=25,phi=\x);
\draw[line width=0.275mm,dashed] plot[variable=\x,domain=\R:\RR](z spherical cs:radius=\x,theta=25,phi=55);
\draw[line width=0.275mm,top color=blue!30,bottom color=blue,shading angle=60,
fill opacity=0.4] plot[variable=\x,domain=30:5](z spherical cs:radius=\R,theta=55-\x,phi=55)
-- plot[variable=\x,domain=55:5](z spherical cs:radius=\R,theta=50,phi=\x)
-- plot[variable=\x,domain=5:30](z spherical cs:radius=\R,theta=55-\x,phi=5)
-- plot[variable=\x,domain=5:55](z spherical cs:radius=\R,theta=25,phi=\x);
\draw[line width=0.275mm,top color=gray,bottom color=gray!50,shading angle=125,
fill opacity=0.4] plot[variable=\x,domain=30:5](z spherical cs:radius=\RR,theta=55-\x,phi=5)
-- plot[variable=\x,domain=\RR:\R](z spherical cs:radius=\x,theta=50,phi=5)
-- plot[variable=\x,domain=5:30](z spherical cs:radius=\R,theta=55-\x,phi=5)
-- plot[variable=\x,domain=\R:\RR](z spherical cs:radius=\x,theta=25,phi=5);
\draw[line width=0.275mm,top color=gray!50!black,bottom color=gray,shading angle=15,
fill opacity=0.4] plot[variable=\x,domain=5:55](z spherical cs:radius=\RR,theta=50,phi=\x)
-- plot[variable=\x,domain=\RR:\R](z spherical cs:radius=\x,theta=50,phi=55)
-- plot[variable=\x,domain=55:5](z spherical cs:radius=\R,theta=50,phi=\x)
-- plot[variable=\x,domain=\R:\RR](z spherical cs:radius=\x,theta=50,phi=5);
\end{tikzpicture}
\end{document}