我正在尝试围绕两个轴旋转一个圆。圆应垂直于红色矢量。
代码:
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% xyz axes
\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,5) node[anchor=north west]{$z$};
% vector
\draw[->,red] (0,0,0) -- (4,4,4);
% center of circle
\fill (3,3,3) circle (1pt);
% circle
\draw (3,3,3) circle (3); % rotation?
\end{tikzpicture}
\end{document}
输出:
我想知道如何旋转圆圈,使红色矢量和圆圈相互垂直。我认为这是绕 y 轴旋转 45°,绕 z 轴旋转 45°,但是如何使用 tikz 实现这一点?
答案1
我建议使用tikz-3dplot
如果您确实想使用 TikZ,因为它将使用专为 2D 绘图而设计的包来处理伪造 3D 所需的许多计算。
例如:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\tdplotsetrotatedcoords{180}{-90}{-90}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[tdplot_rotated_coords]
\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,5,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,5) node[anchor=north west]{$z$};
\draw[->,red] (0,0,0) -- (4,4,4);
\path [fill] (3,3,3) coordinate (c) circle (1pt);
\tdplotdrawarc[tdplot_rotated_coords]{(c)}{3}{0}{360}{}{}
\end{scope}
\end{tikzpicture}
\end{document}
如果我们想给圆圈添加阴影以赋予更多的深度感,我们可以使用该backgrounds
库并关注绘制顺序。例如:
\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{110}
\tdplotsetrotatedcoords{180}{-90}{-90}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[tdplot_rotated_coords]
\draw[thick,->] (0,0,0) coordinate (o) -- (5,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (o) -- (0,5,0) node[anchor=north west]{$y$};
\draw[thick,->] (o) -- (0,0,5) node[anchor=north west]{$z$};
\draw[red] (o) -- (3,3,3) coordinate (c);
\path [fill] (c) circle (1pt);
\begin{scope}[on background layer]
\draw[->,red] (c) -- (4,4,4);
\tdplotdrawarc[tdplot_rotated_coords, right color=blue!50!cyan, left color=blue!50!cyan!15!white, fill opacity=.25, postaction={top color=blue!50!cyan!15!white, bottom color=blue!50!cyan, fill opacity=.25}]{(c)}{3}{0}{360}{}{}
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}