如何在 TikZ 中绘制带有轴和矢量以及一些文本的 3D 球体

如何在 TikZ 中绘制带有轴和矢量以及一些文本的 3D 球体

我试图在 Latex 中重现这个特定的情节。我还想能够在球体的侧面或内部写一些文字。谢谢。

在此处输入图片描述

编辑:我在这里添加了我的尝试以及建议。所以,我基本上明白了,但我无法在 xy 和 xz 平面上添加投影。我尝试使用该包,%\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}但一直收到错误。如果有帮助的话,我正在使用 overleaf。

\documentclass[border=5mm]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{arrows.meta,decorations.markings}
\begin{document}
\begin{tikzpicture}
  \shade[ball color = white!0, opacity = 0] (0,0) circle (2cm);
  \coordinate (O) at (0,0,0);
  %draw the main coordinate system axes
    \draw[-stealth,color=black,->] (0,0,0) -- (2.2,0,0) node[anchor=north east]{$y$};
    \draw[-stealth,color=black,->] (0,0,0) -- (0,2.2,0) node[anchor=north west]{$z$};

    \draw[-stealth,color=black,->] (0,0,0) -- (0,0,4) node[anchor=south]{$x$};

    %draw a vector from origin to point (P) 
    \draw[-stealth,color=black] (0,0,0) -- (0,0,-2.4) node[midway,above] {$r$};


  \draw (0,0) circle (1.3cm);
  \fill[fill=black] (0,0) circle (1pt);
  %\draw[dashed] (0,0 ) -- node[above]{$r$} (2,0);
\end{tikzpicture}
\end{document}

编辑1:

我让这个软件包运行起来,但现在我的预测全都失败了

\documentclass[border=5mm]{standalone}
%\usepackage{tikz}
\usepackage{tikz,tikz-3dplot}
\usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\usetikzlibrary{arrows.meta,decorations.markings}
\begin{document}
\pgfmathsetmacro{\rvec}{4} %1.6
\pgfmathsetmacro{\thetavec}{45}
\pgfmathsetmacro{\phivec}{40}
%\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}%[scale=5,tdplot_main_coords]
  \shade[ball color = white!0, opacity = 0] (0,0) circle (2cm);
  \coordinate (O) at (0,0,0);
  \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
  %draw the main coordinate system axes
    \draw[-stealth,color=black] (0,0,0) -- (2.2,0,0) node[anchor=north east]{$y$};
    \draw[-stealth,color=black] (0,0,0) -- (0,2.2,0) node[anchor=north west]{$z$};
    %\draw[thick,->] (0,0,-2.4) -- (0,0,3) 
    \draw[-stealth,color=black] (0,0,0) -- (0,0,4) node[anchor=south]{$x$};

    %draw a vector from origin to point (P) 
    \draw[-stealth,color=red] (O) -- (P);
    %\draw[-stealth,color=black] (0,0,0) -- (0,0,-2.4) node[midway,above] {$r$};

    %draw projection on xy plane, and a connecting line
    \draw[dashed, color=red] (O) -- (Pxy);
    \draw[dashed, color=red] (P) -- (Pxy);

  \draw (0,0) circle (1.3cm);
  \fill[fill=black] (0,0) circle (1pt);
  %\draw[dashed] (0,0 ) -- node[above]{$r$} (2,0);
\end{tikzpicture}
\end{document}

答案1

大约十年前,我在量子力学和轨道理论课上画了一张类似的图。我是这样进行的:

\documentclass[a4paper,11pt]{article}

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

\usetikzlibrary{calc,arrows,patterns}

\usepackage[]{caption}
\setlength{\abovecaptionskip}{0pt}
\setlength{\belowcaptionskip}{0pt}

\usepackage[body={17.0cm,26cm},top=2.0cm,left=2.0cm]{geometry}

\begin{document}
    
        \tdplotsetmaincoords{70}{115}
        % bepaalt aspect van het assenstelsel
        \pgfmathsetmacro{\rvec}{0.9}
        \pgfmathsetmacro{\thetavec}{35}
        \pgfmathsetmacro{\phivec}{60}
        % bepaalt de grootte en orientatie van de bolvectoren
        \begin{tikzpicture}[scale=4,tdplot_main_coords]
            \coordinate (O) at (0,0,0);
            %---- draw axis
            \draw[thin,solid,->] (0,0,0) -- (1.25,0,0) node[anchor=north east]{$x$};
            \draw[thin,solid,->] (0,0,0) -- (0,1.25,0) node[anchor=north west]{$y$};
            \draw[thin,solid,->] (0,0,0) -- (0,0,1.25) node[anchor=south]{$z$};
            %---- draw vector P and projections
            \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
            \draw[thick,-stealth,color=red] (O) -- (P) node[color=blue,midway,anchor=north west]{\textbf{r}} node[anchor=south west]{$P$};
            \draw[thick, dotted, color=red] (O) -- (Pxy);
            \draw[thick, dotted, color=red] (P) -- (Pxy);
            %---- draw spherical angles
            \tdplotdrawarc{(O)}{0.2}{0}{\phivec}{color=blue,anchor=north}{$\varphi$}
            \tdplotsetthetaplanecoords{\phivec}
            \tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{0}{\thetavec}{color=blue,anchor=south west}{$\vartheta$}
            \draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
            \draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
            %---- annotate movement of P on circle
            \draw[thick,dotted,color=green,<->] (-0.1,0,0.53) arc (20:70:0.55) node[color=green,anchor=west]{$\varphi+\Delta\varphi$};
            \node[color=green,anchor=east] at (-0.1,0,0.53) {$\varphi-\Delta\varphi$};
            %---- draw circle
            \draw[thick, dotted] (0,0) circle[radius=1,rotate=90];
        \end{tikzpicture}
        \vspace{18pt}
        \captionof{figure}{Definitie van het sferische stelsel ($r,\varphi,\vartheta$) t.o.v. het rechthoekig stelsel (\textit{x,y,z}). Een verplaatsing in het (\textit{x,y})-vlak wordt een verandering in $\varphi$.}
        \label{fig:def_sfcor}
    
\end{document}

也许您可以使用我注释图表的方式来帮助您找到答案。

相关内容