我正在探索用于在 3D 中绘制对象的包,遇到了一个问题。我只是想画一个圆,然后稍后引用一些点,但我发现使用该命令和使用以下命令tikz-3dplot
时存在差异:draw
node
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\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$};
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{1}{70}{40}
\draw[-stealth,color=blue] (O) -- (P);
\node[draw, circle, radius=0.2] (cir) at (P) {};
\draw[red] (P) circle [radius=0.2];
\draw (cir.south) -- (cir.north);
\end{tikzpicture}%
\end{document}
为什么会有差异?我想使用,node
因为我可以参考,例如,南点和北点以供以后使用,可能是投影。但使用node
不能提供正确的形状(我希望用红色圆圈绘制,node
以便我可以参考它)。我不明白为什么node
不使用tdplot_main_coords
坐标系。谢谢。
答案1
这是因为默认情况下圆是在 xy 平面中绘制的。您可以在屏幕坐标中绘制圆,以便与节点“同步”。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\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$};
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{1}{70}{40}
\draw[-stealth,color=blue] (O) -- (P);
\node[draw, circle, radius=0.2] (cir) at (P) {};
\draw[red,tdplot_screen_coords] (P) circle [radius=0.2];
\draw (cir.south) -- (cir.north);
\end{tikzpicture}%
\end{document}
如果您希望在平面上绘制节点xy
,可以使用3d
库来完成。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\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$};
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{1}{70}{40}
\draw[-stealth,color=blue] (O) -- (P);
\begin{scope}[canvas is xy plane at z=0,transform shape]
\node[draw, circle, radius=0.2] (cir) at (P) {};
\end{scope}
\draw[red] (P) circle [radius=0.2];
\draw (cir.south) -- (cir.north);
\end{tikzpicture}%
\end{document}