凭借我对 tikz 的基本了解,我想在我的课堂笔记中加上有限旋转不是交换的。这是我的代码。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1]
% Initial position
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,1,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
\draw[thick,fill=gray!30,opacity=0.5] (-1,-0.5,0) -- (-1,0.5,0) -- (1,0.5,0) -- (1,-0.5,0) -- cycle;
\draw[thick, dashed,red] (-1,-0.5,0) -- (1,0.5,0);
\draw[thick, dashed,blue] (-1,0.5,0) -- (1,-0.5,0);
%\node at (0,0,0) {\footnotesize Math};
% Rotation autour de x
\begin{scope}[xshift=5cm]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,1,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
\draw[thick,fill=gray!50,opacity=0.5] (-1,0,0.5) -- (-1,0,-0.5) -- (1,0,-0.5) -- (1,0,0.5) -- cycle;
\draw[thick, dashed,red] (-1,0,0.5) -- (1,0,-0.5);
\draw[thick, dashed,blue] (-1,0,-0.5) -- (1,0,0.5);
%\node[rotate=-45,yslant=1] at (0,0,0) {\footnotesize Math};
\end{scope}
% Rotation autour de y
\begin{scope}[xshift=10cm]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,1,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
\draw[thick,fill=gray!70,opacity=0.5] (0.5,0,-1) -- (-0.5,0,-1) -- (-0.5,0,1) -- (0.5,0,1) -- cycle;
% Diagonales après rotation
\draw[thick, dashed,red] (0.5,0,1) -- (-0.5,0,-1);
\draw[thick, dashed,blue] (-0.5,0,1) -- (0.5,0,-1);
%\node[rotate=45,xslant=-1] at (0,0,0) {\footnotesize Math};
\end{scope}
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}[scale=1]
% Initial position
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,1,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
\draw[thick,fill=gray!30,opacity=0.5] (-1,-0.5,0) -- (-1,0.5,0) -- (1,0.5,0) -- (1,-0.5,0) -- cycle;
\draw[thick, dashed,red] (-1,-0.5,0) -- (1,0.5,0);
\draw[thick, dashed,blue] (-1,0.5,0) -- (1,-0.5,0);
%\node at (0,0,0) {\footnotesize Math};
\begin{scope}[xshift=5cm]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,1,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
\draw[thick,fill=gray!30,opacity=0.5] (0,-0.5,1) -- (0,-0.5,-1) -- (0,0.5,-1) -- (0,0.5,1) -- cycle;
% Diagonales après rotation
\draw[thick, dashed,blue] (0,-0.5,-1) -- (0,0.5,1);
\draw[thick, dashed,red] (0,0.5,-1) -- (0,-0.5,1);
%\node[rotate=-90,yslant=1] at (0,0,0) {\footnotesize Math};
\end{scope}
\begin{scope}[xshift=10cm]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,1,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,3) node[above] {$z$};
\draw[thick,fill=gray!30,opacity=0.5] (0,1,0.5) -- (0,1,-0.5) -- (0,-1,-0.5) -- (0,-1,0.5) -- cycle;
% Diagonales après rotation
\draw[thick, dashed,blue] (0,-1,0.5) -- (0,1,-0.5);
\draw[thick, dashed,red] (0,-1,-0.5) -- (0,1,0.5);
%\node[rotate=-90,yslant=1] at (0,0,0) {\footnotesize Math};
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}
然而,这需要大量的手工工作,结果可能会更令人满意。任何帮助都将不胜感激。
答案1
Tikz-3dplot 使旋转更容易,但有一定的限制。主坐标对应于 POV 的纬度和经度,因此 z 轴始终向上(或向下)。旋转的坐标很容易绕 y 轴或 z 轴旋转,但绕 x 轴旋转需要三次旋转。
这是为了演示可用的旋转,而不是交换性质。
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,2,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,2) node[above] {$z$};
\draw[thick,fill=gray!30,opacity=0.5] (-1,-0.5,0) -- (-1,0.5,0) -- (1,0.5,0) -- (1,-0.5,0) -- cycle;
\draw[thick, dashed,red] (-1,-0.5,0) -- (1,0.5,0);
\draw[thick, dashed,blue] (-1,0.5,0) -- (1,-0.5,0);
\end{tikzpicture}
\hfill
\begin{tikzpicture}[tdplot_main_coords]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,2,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,2) node[above] {$z$};
\tdplotsetrotatedcoords{90}{0}{0}% rotate around z axis
\begin{scope}[tdplot_rotated_coords]
\draw[thick,fill=gray!30,opacity=0.5] (-1,-0.5,0) -- (-1,0.5,0) -- (1,0.5,0) -- (1,-0.5,0) -- cycle;
\draw[thick, dashed,red] (-1,-0.5,0) -- (1,0.5,0);
\draw[thick, dashed,blue] (-1,0.5,0) -- (1,-0.5,0);
\end{scope}
\end{tikzpicture}
\hfill
\begin{tikzpicture}[tdplot_main_coords]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,2,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,2) node[above] {$z$};
\tdplotsetrotatedcoords{0}{90}{0}% rotate around y axis
\begin{scope}[tdplot_rotated_coords]
\draw[thick,fill=gray!30,opacity=0.5] (-1,-0.5,0) -- (-1,0.5,0) -- (1,0.5,0) -- (1,-0.5,0) -- cycle;
\draw[thick, dashed,red] (-1,-0.5,0) -- (1,0.5,0);
\draw[thick, dashed,blue] (-1,0.5,0) -- (1,-0.5,0);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[tdplot_main_coords]
\draw[->] (0,0,0) -- (2,0,0) node[right] {$x$};
\draw[->] (0,0,0) -- (0,2,0) node[above] {$y$};
\draw[->] (0,0,0) -- (0,0,2) node[above] {$z$};
\tdplotsetrotatedcoords{90}{90}{-90}% rotate rround x axis
\begin{scope}[tdplot_rotated_coords]
\draw[thick,fill=gray!30,opacity=0.5] (-1,-0.5,0) -- (-1,0.5,0) -- (1,0.5,0) -- (1,-0.5,0) -- cycle;
\draw[thick, dashed,red] (-1,-0.5,0) -- (1,0.5,0);
\draw[thick, dashed,blue] (-1,0.5,0) -- (1,-0.5,0);
\end{scope}
\end{tikzpicture}
\end{document}