我正在尝试在 tikz 3d 中绘制一个封闭的圆环,请参阅下面的 MWE。我希望第一张图片的表面为灰色,第二张图片中蓝线以下的所有内容为灰色。是否可以做到这一点并尽可能少地更改图片(这样它仍然与我制作的其他图片保持相同的风格)?
提前致谢
\documentclass[tikz,border=1.618mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{tikz-cd}
\usepackage[]{calc}
\begin{document}
\tdplotsetmaincoords{80}{0}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\tdplotsetrotatedcoords{90}{90}{0}
\tdplotdrawarc[bottom color= gray, top color= gray!40, tdplot_main_coords]{(0,-0.08,0.76604444311)}{0.64278760968}{0}{360}{}{}
\tdplotdrawarc[tdplot_rotated_coords]{(O)}{1}{-140.5}{140.5}{}{}
\tdplotdrawarc[tdplot_rotated_coords]{(O)}{.25}{0}{360}{}{}
\end{tikzpicture}
\tdplotsetmaincoords{80}{0}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\tdplotsetrotatedcoords{90}{90}{0}
\tdplotdrawarc[tdplot_main_coords,color=blue, dashed]{(0,-0.08,0.76604444311)}{0.64278760968}{0}{180}{}{}
\tdplotdrawarc[tdplot_main_coords,color=blue]{(0,-0.08,0.76604444311)}{0.64278760968}{180}{360}{}{}
\tdplotdrawarc[tdplot_rotated_coords]{(O)}{1}{-140.5}{140.5}{}{}
\tdplotdrawarc[tdplot_rotated_coords]{(O)}{.25}{0}{360}{}{}
\tdplotsetrotatedcoords{90}{-90}{0}
\tdplotdrawarc[tdplot_rotated_coords, color=blue]{(O)}{1}{-39.5}{39.5}{}{}
\end{tikzpicture}
\end{document}
答案1
恐怕我无法(或不愿意)根据您提供的精确代码给出答案,因为我不明白所有神奇数字从何而来。不过,计算临界角很容易,有了这些信息,着色就很简单了。
\documentclass[tikz,border=1.618mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{80}{0}
\begin{tikzpicture}[scale=5,tdplot_main_coords,
declare function={h=0.75;
tcrit(\x)=atan2(sin(\x),cos(\x)*sin(\tdplotmaintheta));},
radius=1]
\pgfmathsetmacro{\myalpha}{tcrit(asin(h))}
\pgfmathsetmacro{\myr}{sqrt(1-h*h)}
\coordinate (O) at (0,0,0);
\draw[bottom color= gray, top color= gray!40, tdplot_main_coords] (0,0,h) circle[radius=\myr];
\draw[fill=gray,even odd rule]
[tdplot_main_coords]
(0,0,h)+(90+\tdplotmaintheta:\myr) arc[start angle=90+\tdplotmaintheta,end angle=450-\tdplotmaintheta,radius=\myr]
[tdplot_screen_coords] -- (\myalpha:1) arc[start angle=\myalpha,end angle=-180-\myalpha] (O) circle[radius=0.25];
\end{tikzpicture}
\tdplotsetmaincoords{80}{0}
\begin{tikzpicture}[scale=5,tdplot_main_coords,
declare function={h=0.75;
tcrit(\x)=atan2(sin(\x),cos(\x)*sin(\tdplotmaintheta));},
radius=1]
\pgfmathsetmacro{\myalpha}{tcrit(asin(h))}
\pgfmathsetmacro{\myr}{sqrt(1-h*h)}
\coordinate (O) at (0,0,0);
\draw[fill=gray,even odd rule]
[tdplot_main_coords]
(0,0,h)+(90+\tdplotmaintheta:\myr) arc[start angle=90+\tdplotmaintheta,end angle=450-\tdplotmaintheta,radius=\myr]
[tdplot_screen_coords] -- (\myalpha:1) arc[start angle=\myalpha,end angle=-180-\myalpha] (O) circle[radius=0.25];
\draw[dashed,blue] [tdplot_main_coords]
(0,0,h)+(90+\tdplotmaintheta:\myr) arc[start angle=90+\tdplotmaintheta,end angle=90-\tdplotmaintheta,radius=\myr];
\draw[blue,tdplot_screen_coords] (\myalpha:1) arc[start angle=\myalpha,end angle=180-\myalpha];
\end{tikzpicture}
\end{document}