沿 z 轴绘制两个相隔水平距离的球体

沿 z 轴绘制两个相隔水平距离的球体

我想绘制另一个类似下面的球体,包括轴、线和角(它们全部“带引号”),但偏移了 (0,0,5),即沿 z 轴偏移 5。

我想让两个球体都位于同一个 tikzpicture 中。我尝试了很多方法,但都不能完美地工作。我遇到的一个问题是该\shade命令使用屏幕坐标 ( tdplot_screen_coords),这使得很难将第二个球体精确地置于 (0,0,5) 的中心。我也尝试过\tdplotsetrotatedcoordsorigin{(Shift)},但我无法用它移动所有元素。

我该如何绘制第二个球体?我几乎要放弃了,而是使用 OpenGL 构建图像。

球面坐标系

\documentclass[preprint,12pt]{article}

\usepackage{tikz}
\usepackage{tikz-3dplot}

\begin{document}

\tdplotsetmaincoords{60}{110}
\tdplotsetrotatedcoords{-90}{-90}{0}
%
\resizebox{10cm}{!}%
{
\begin{tikzpicture}[scale=3,tdplot_rotated_coords]
  % Origens e pontos:
  \coordinate (O) at (0,0,0);
  % Eixos na origem 1:
  \draw[thick,->] (O) -- (1.5,0,0) node[anchor=north east]{$x$};
  \draw[thick,->] (O) -- (0,1.5,0) node[anchor=north west]{$y$};
  \draw[thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z$};
  % 
  \def\rvec{1}
  \def\thetavec{45}
  \def\phivec{30}
  %
  \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
  % Preencher esfera 1:
  \shade[tdplot_screen_coords, ball color = white, opacity=.5]     (0,0,0) circle (\rvec);
  % Linha da origem ao ponto:
  \draw[-stealth,color=red] (O) -- (P) node[above right] {$P$};
  % Linhas aos planos:
  \draw[dashed, color=red] (O) -- (Pxy);
  \draw[dashed, color=red] (P) -- (Pxy);
  % Angulos:
  \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.2}{0}{\phivec}{anchor=north east}{$\phi$}
  \tdplotsetrotatedthetaplanecoords{\phivec}
  \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
\end{tikzpicture}
}

\end{document}

答案1

我不太确定这是否是您想要的。这会将第二个阴影圆放置在(0,0,5)相对于旋转坐标系的位置,即(0,5,0)相对于主坐标系的位置。

我添加了细蓝轴来显示主坐标系的坐标轴,并添加了细绿轴来显示平移旋转坐标系的坐标轴(相对于该坐标系绘制了附加圆)。显然,这些只是为了解释目的。

主旋转和平移旋转坐标系

\documentclass[border=10pt,tikz,multi]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{110}
\tdplotsetrotatedcoords{-90}{-90}{0}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
  \coordinate (O) at (0,0,0);
  \coordinate (o) at (0,5,0);
  \draw [->, blue, thin] (O) -- (1.75,0,0) node[anchor=north east]{$x$};
  \draw [->, blue, thin] (O) -- (0,1.75,0) node[anchor=north west]{$y$};
  \draw [->, blue, thin] (O) -- (0,0,1.75) node[anchor=south]{$z$};
  \begin{scope}[tdplot_rotated_coords]
    \draw [thick,->] (O) -- (1.5,0,0) node[anchor=north east]{$x$};
    \draw [thick,->] (O) -- (0,1.5,0) node[anchor=north west]{$y$};
    \draw [thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z$};
    \def\rvec{1}
    \def\thetavec{45}
    \def\phivec{30}
    \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
    \shade[tdplot_screen_coords, ball color = white, opacity=.5] (0,0,0) circle (\rvec);
    \draw[-stealth, color=red] (O) -- (P) node[above right] {$P$};
    \draw[dashed, color=red] (O) -- (Pxy);
    \draw[dashed, color=red] (P) -- (Pxy);
    \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.2}{0}{\phivec}{anchor=north east}{$\phi$}
    \tdplotsetrotatedthetaplanecoords{\phivec}
    \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
  \end{scope}
  \tdplotsetrotatedcoords{-90}{-90}{0}
  \tdplotsetrotatedcoordsorigin{(o)}
  \begin{scope}[tdplot_rotated_coords]
    \draw [thin, green, ->] (o) -- (1.5,0,0) node[anchor=north east]{$x$};
    \draw [thin, green, ->] (o) -- (0,1.5,0) node[anchor=north west]{$y$};
    \draw [thin, green, ->] (o) -- (0,0,1.5) node[anchor=south]{$z$};
    \def\rvec{1}
    \shade[tdplot_screen_coords, ball color = white, opacity=.5] (0,0,0) circle (\rvec);
  \end{scope}
\end{tikzpicture}
\end{document}

然而,这仅仅相当于

\begin{tikzpicture}[scale=3,tdplot_main_coords]
  \coordinate (O) at (0,0,0);
  \coordinate (o) at (0,5,0);
  \draw [->, blue, thin] (O) -- (1.75,0,0) node[anchor=north east]{$x$};
  \draw [->, blue, thin] (O) -- (0,1.75,0) node[anchor=north west]{$y$};
  \draw [->, blue, thin] (O) -- (0,0,1.75) node[anchor=south]{$z$};
  \begin{scope}[tdplot_rotated_coords]
    \draw [thick,->] (O) -- (1.5,0,0) node[anchor=north east]{$x$};
    \draw [thick,->] (O) -- (0,1.5,0) node[anchor=north west]{$y$};
    \draw [thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z$};
    \def\rvec{1}
    \def\thetavec{45}
    \def\phivec{30}
    \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
    \shade[tdplot_screen_coords, ball color = white, opacity=.5] (0,0,0) circle (\rvec);
    \draw[-stealth, color=red] (O) -- (P) node[above right] {$P$};
    \draw[dashed, color=red] (O) -- (Pxy);
    \draw[dashed, color=red] (P) -- (Pxy);
    \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.2}{0}{\phivec}{anchor=north east}{$\phi$}
    \tdplotsetrotatedthetaplanecoords{\phivec}
    \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
  \end{scope}
  \shade[tdplot_screen_coords, ball color = white, opacity=.5] (o) circle (1);
\end{tikzpicture}

除了我没有添加绿轴,因为在这种情况下坐标系既没有旋转也没有平移。

主坐标系和旋转坐标系

我之所以包含第一个版本,只是因为你可能真的想要这样的东西

两个完整的圆形物体

\begin{tikzpicture}[scale=3,tdplot_main_coords]
  \coordinate (O) at (0,0,0);
  \coordinate (o) at (0,5,0);
  \draw [->, blue, thin] (O) -- (1.75,0,0) node[anchor=north east]{$x$};
  \draw [->, blue, thin] (O) -- (0,1.75,0) node[anchor=north west]{$y$};
  \draw [->, blue, thin] (O) -- (0,0,1.75) node[anchor=south]{$z$};
  \begin{scope}[tdplot_rotated_coords]
    \draw [thick,->] (O) -- (1.5,0,0) node[anchor=north east]{$x$};
    \draw [thick,->] (O) -- (0,1.5,0) node[anchor=north west]{$y$};
    \draw [thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z$};
    \def\rvec{1}
    \def\thetavec{45}
    \def\phivec{30}
    \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
    \shade[tdplot_screen_coords, ball color = white, opacity=.5] (0,0,0) circle (\rvec);
    \draw[-stealth, color=red] (O) -- (P) node[above right] {$P$};
    \draw[dashed, color=red] (O) -- (Pxy);
    \draw[dashed, color=red] (P) -- (Pxy);
    \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.2}{0}{\phivec}{anchor=north east}{$\phi$}
    \tdplotsetrotatedthetaplanecoords{\phivec}
    \tdplotdrawarc[tdplot_rotated_coords]{(O)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
  \end{scope}
  \tdplotsetrotatedcoords{-90}{-90}{0}
  \tdplotsetrotatedcoordsorigin{(o)}
  \begin{scope}[tdplot_rotated_coords]
    \draw [thin, green, ->] (o) -- (1.5,0,0) node[anchor=north east]{$x$};
    \draw [thin, green, ->] (o) -- (0,1.5,0) node[anchor=north west]{$y$};
    \draw [thin, green, ->] (o) -- (0,0,1.5) node[anchor=south]{$z$};
    \def\rvec{1}
    \def\thetavec{45}
    \def\phivec{30}
    \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
    \shade[tdplot_screen_coords, ball color = white, opacity=.5] (o) circle (\rvec);
    \draw [-stealth, color=red] (o) -- (P) node[above right] {$P$};
    \draw [dashed, color=red] (o) -- (Pxy);
    \draw [dashed, color=red] (P) -- (Pxy);
    \tdplotdrawarc[tdplot_rotated_coords]{(o)}{0.2}{0}{\phivec}{anchor=north east}{$\phi$}
    \tdplotsetrotatedthetaplanecoords{\phivec}
    \tdplotdrawarc[tdplot_rotated_coords]{(o)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
  \end{scope}
\end{tikzpicture}

相关内容