我正在使用 tikz 绘制坐标系,我打算使用箭头表示圆弧\phi
和\theta
。但是当我在圆弧选项中使用 ->(得到正确的圆弧)时,图形内部仍然会出现不需要的 ^
如何解决这个问题?(见下文“几乎 MWE”)
\documentclass{article}
\usepackage{tikz} %TikZ is required for this to work. Make sure this exists before the next line
\usepackage{3dplot} %requires 3dplot.sty to be in same directory, or in your LaTeX installation
\usepackage[active,tightpage]{preview} %generates a tightly fitting border around the work
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\begin{document}
\tdplotsetmaincoords{60}{110}
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{60}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\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,0) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=red] (O) -- (P);
\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}{0}{\thetavec}{anchor=south west}{$\theta$}
\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
\draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
\end{tikzpicture}
\end{document}
答案1
代码的问题在于您使用的是旧版本的软件包3dplot
。它已被替换为tikz-3dplot
具有您所需功能的新版本。因此修复非常简单。
\documentclass{article}
\usepackage{tikz}
% \usepackage{3dplot} % old package
\usepackage{tikz-3dplot} % new package
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\begin{document}
\tdplotsetmaincoords{60}{110}
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{60}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\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,0) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=red] (O) -- (P);
\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}{0}{\thetavec}{anchor=south west}{$\theta$}
\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
\draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
\end{tikzpicture}
\end{document}