我正在使用这个代码:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{45}{135}
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{45}
\pgfmathsetmacro{\phivec}{75}
\begin{tikzpicture}[scale=9,tdplot_main_coords]
\shade[tdplot_screen_coords,ball color = gray!60] (0,0) circle (\rvec);
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=black] (O) -- (P) node[midway,above] {$r$};
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{\thetavec}{90}{anchor=south west}{$\theta$}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{\rvec}{-180}{180}{anchor=south west}{}
\end{tikzpicture}
\end{document}
这将创建:
如何应用递减的径向渐变?
预期结果将是类似于(轴等保持可见):
答案1
如果您只想要径向衰落,那么第 23.4.2 节之前的示例可能是可行的方法。
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{fadings}
\tikzfading[name=fade out,
inner color=transparent!0,
outer color=transparent!100]
\begin{document}
\tdplotsetmaincoords{45}{135}
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{45}
\pgfmathsetmacro{\phivec}{75}
\begin{tikzpicture}[scale=9,tdplot_main_coords]
\fill[tdplot_screen_coords,gray!40!black,%ball color = gray,
path fading=fade out] (0,0) circle (\rvec);
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=black] (O) -- (P) node[midway,above] {$r$};
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{\thetavec}{90}{anchor=south west}{$\theta$}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{\rvec}{-180}{180}{anchor=south west}{}
\end{tikzpicture}
\end{document}
另一个选择是稍微修改shadings
库中的模糊圆圈。(我只是从库中复制并稍微修改了模糊圆圈的淡入淡出,以便您可以立即访问不同距离的透明度级别。我并不是说我的选择特别好,但最终您需要自己决定最适合您的选择。数字 23 实际上并不代表百分比,但如果您打篮球,您可能会理解我为什么选择它。;-)
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{fadings}
\makeatletter
\pgfdeclareradialshading{tikz@lib@fade@circle@23}{\pgfpointorigin}{
color(0pt)=(pgftransparent!0); color(20bp)=(pgftransparent!50);
color(25bp)=(pgftransparent!92); color(50bp)=(pgftransparent!100)}
\pgfdeclarefading{circle with fuzzy edge 23 percent}{\pgfuseshading{tikz@lib@fade@circle@23}}
\makeatother
\tikzfading[name=fade out,
inner color=transparent!0,
outer color=transparent!100]
\begin{document}
\tdplotsetmaincoords{45}{135}
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{45}
\pgfmathsetmacro{\phivec}{75}
\begin{tikzpicture}[scale=9,tdplot_main_coords]
\shade[tdplot_screen_coords,ball color=gray!60,
path fading={circle with fuzzy edge 23 percent}] (0,0) circle (\rvec);
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,-1) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=black] (O) -- (P) node[midway,above] {$r$};
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{\thetavec}{90}{anchor=south west}{$\theta$}
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{\rvec}{-180}{180}{anchor=south west}{}
\end{tikzpicture}
\end{document}