考虑以下代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{amsmath}
\newcommand{\ptsize}{1.5pt}
\usepackage{xcolor}
\definecolor{MyColor1}{rgb}{0.24, 0.59, 0.32}
\definecolor{MyColor2}{rgb}{0.85, 0.49, 0.19}
\definecolor{MyColor3}{rgb}{0.22, 0.42, 0.69}
\begin{document}
\tdplotsetmaincoords{75}{130}
\begin{tikzpicture}[tdplot_main_coords]
% Define all the nodes necessary for the drawing
\coordinate (alpha1) at (1,-1,0);
\coordinate (alpha2) at (0,1,-1);
\coordinate (alpha3) at (0,0,2);
\coordinate (12) at ($ (alpha1) + (alpha2) $);
\coordinate (23) at ($ (alpha2) + (alpha3) $);
\coordinate (123) at ($ (alpha1) + (alpha2) + (alpha3) $);
\coordinate (223) at ($ (alpha2) + (alpha2) + (alpha3) $);
\coordinate (1223) at ($ (alpha1) + (alpha2) + (alpha2) + (alpha3) $);
\coordinate (11223) at ($ (alpha1) + (alpha1) + (alpha2) + (alpha2) + (alpha3) $);
\coordinate (-alpha1) at (-1,1,0);
\coordinate (-alpha2) at (0,-1,1);
\coordinate (-alpha3) at (0,0,-2);
\coordinate (-12) at ($ (-alpha1) + (-alpha2) $);
\coordinate (-23) at ($ (-alpha2) + (-alpha3) $);
\coordinate (-123) at ($ (-alpha1) + (-alpha2) + (-alpha3) $);
\coordinate (-223) at ($ (-alpha2) + (-alpha2) + (-alpha3) $);
\coordinate (-1223) at ($ (-alpha1) + (-alpha2) + (-alpha2) + (-alpha3) $);
\coordinate (-11223) at ($ (-alpha1) + (-alpha1) + (-alpha2) + (-alpha2) + (-alpha3) $);
% Draw the black polygon
\begin{scope}[opacity=0.5]
\draw (alpha3) -- (11223) -- (-alpha3) -- (-11223) -- (alpha3);
\draw (alpha3) -- (223) -- (-alpha3) -- (-223) -- (alpha3);
\end{scope}
% Draw the nodes for the roots in appropriate colors
\begin{scope}[MyColor3]
\draw[fill] (alpha3) circle (\ptsize);
\draw[fill] (-alpha3) circle (\ptsize);
\end{scope}
\begin{scope}[MyColor2]
\draw[fill] (alpha1) circle (\ptsize);
\draw[fill] (223) circle (\ptsize);
\draw[fill] (1223) circle (\ptsize);
\draw[fill] (11223) circle (\ptsize);
\draw[fill] (-alpha1) circle (\ptsize);
\draw[fill] (-223) circle (\ptsize);
\draw[fill] (-1223) circle (\ptsize);
\draw[fill] (-11223) circle (\ptsize);
\end{scope}
\begin{scope}[MyColor1]
\draw[fill] (alpha2) circle (\ptsize);
\draw[fill] (12) circle (\ptsize);
\draw[fill] (23) circle (\ptsize);
\draw[fill] (123) circle (\ptsize);
\draw[fill] (-alpha2) circle (\ptsize);
\draw[fill] (-12) circle (\ptsize);
\draw[fill] (-23) circle (\ptsize);
\draw[fill] (-123) circle (\ptsize);
\end{scope}
% Draw the orange rectangle
\draw[MyColor2] (11223) -- (223) -- (-11223) -- (-223) -- (11223);
% Draw the upper green rectangle
\draw[MyColor1] (-alpha2) -- (123) -- (23) -- (-12) -- (-alpha2);
% Draw the upper green rectangle
\draw[MyColor1] (12) -- (-23) -- (-123) -- (alpha2) -- (12);
% Nodes for the names
\node (alpha1-name) at (1.4,-1,0) {$\alpha_1$};
\node (alpha2-name) at (0,1.4,-1) {$\alpha_2$};
\node (alpha3-name) at (0,0,2.3) {$\alpha_3$};
\begin{scope}[shift={(0,0,15)}]
\draw[dashed] (alpha1) -- (1223) -- (-alpha1) -- (-1223) -- (alpha1);
\end{scope}
\end{tikzpicture}
\end{document}
产生图片
z
我目前正在尝试将虚线矩形沿图形的 -方向移动一定量。以下这我的尝试可以在上面的代码中找到
\begin{scope}[shift={(0,0,15)}]
\draw[dashed] (alpha1) -- (1223) -- (-alpha1) -- (-1223) -- (alpha1);
\end{scope}
但这不会产生任何变化。所以大概我误解了这个shift
命令应该如何工作...理想情况下,我想在移位矩形的边缘定义新坐标,但我不确定是否可以做到这一点。
答案1
符号坐标不会以这种方式转换。您可以使用 来转换它们transform canvas
,例如
\begin{scope}[transform canvas={shift={(0,0,2)}}]
\draw[dashed] (alpha1) -- (1223) -- (-alpha1) -- (-1223) -- (alpha1);
\end{scope}
但是,这有点危险,例如边界框无法正确计算。另一方面,tikz-3dplot
加载calc
库,因此您可以这样做
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usepackage{amsmath}
\newcommand{\ptsize}{1.5pt}
\usepackage{xcolor}
\definecolor{MyColor1}{rgb}{0.24, 0.59, 0.32}
\definecolor{MyColor2}{rgb}{0.85, 0.49, 0.19}
\definecolor{MyColor3}{rgb}{0.22, 0.42, 0.69}
\begin{document}
\tdplotsetmaincoords{75}{130}
\begin{tikzpicture}[tdplot_main_coords]
% Define all the nodes necessary for the drawing
\coordinate (alpha1) at (1,-1,0);
\coordinate (alpha2) at (0,1,-1);
\coordinate (alpha3) at (0,0,2);
\coordinate (12) at ($ (alpha1) + (alpha2) $);
\coordinate (23) at ($ (alpha2) + (alpha3) $);
\coordinate (123) at ($ (alpha1) + (alpha2) + (alpha3) $);
\coordinate (223) at ($ (alpha2) + (alpha2) + (alpha3) $);
\coordinate (1223) at ($ (alpha1) + (alpha2) + (alpha2) + (alpha3) $);
\coordinate (11223) at ($ (alpha1) + (alpha1) + (alpha2) + (alpha2) + (alpha3) $);
\coordinate (-alpha1) at (-1,1,0);
\coordinate (-alpha2) at (0,-1,1);
\coordinate (-alpha3) at (0,0,-2);
\coordinate (-12) at ($ (-alpha1) + (-alpha2) $);
\coordinate (-23) at ($ (-alpha2) + (-alpha3) $);
\coordinate (-123) at ($ (-alpha1) + (-alpha2) + (-alpha3) $);
\coordinate (-223) at ($ (-alpha2) + (-alpha2) + (-alpha3) $);
\coordinate (-1223) at ($ (-alpha1) + (-alpha2) + (-alpha2) + (-alpha3) $);
\coordinate (-11223) at ($ (-alpha1) + (-alpha1) + (-alpha2) + (-alpha2) + (-alpha3) $);
% Draw the black polygon
\begin{scope}[opacity=0.5]
\draw (alpha3) -- (11223) -- (-alpha3) -- (-11223) -- (alpha3);
\draw (alpha3) -- (223) -- (-alpha3) -- (-223) -- (alpha3);
\end{scope}
% Draw the nodes for the roots in appropriate colors
\begin{scope}[MyColor3]
\draw[fill] (alpha3) circle (\ptsize);
\draw[fill] (-alpha3) circle (\ptsize);
\end{scope}
\begin{scope}[MyColor2]
\draw[fill] (alpha1) circle (\ptsize);
\draw[fill] (223) circle (\ptsize);
\draw[fill] (1223) circle (\ptsize);
\draw[fill] (11223) circle (\ptsize);
\draw[fill] (-alpha1) circle (\ptsize);
\draw[fill] (-223) circle (\ptsize);
\draw[fill] (-1223) circle (\ptsize);
\draw[fill] (-11223) circle (\ptsize);
\end{scope}
\begin{scope}[MyColor1]
\draw[fill] (alpha2) circle[radius=\ptsize];
\draw[fill] (12) circle[radius=\ptsize];
\draw[fill] (23) circle[radius=\ptsize];
\draw[fill] (123) circle[radius=\ptsize];
\draw[fill] (-alpha2) circle[radius=\ptsize];
\draw[fill] (-12) circle[radius=\ptsize];
\draw[fill] (-23) circle[radius=\ptsize];
\draw[fill] (-123) circle[radius=\ptsize];
\end{scope}
% Draw the orange rectangle
\draw[MyColor2] (11223) -- (223) -- (-11223) -- (-223) -- (11223);
% Draw the upper green rectangle
\draw[MyColor1] (-alpha2) -- (123) -- (23) -- (-12) -- (-alpha2);
% Draw the upper green rectangle
\draw[MyColor1] (12) -- (-23) -- (-123) -- (alpha2) -- (12);
% Nodes for the names
\node (alpha1-name) at (1.4,-1,0) {$\alpha_1$};
\node (alpha2-name) at (0,1.4,-1) {$\alpha_2$};
\node (alpha3-name) at (0,0,2.3) {$\alpha_3$};
%\begin{scope}[transform canvas={shift={(0,0,2)}}]
\draw[dashed] ($(alpha1)+(0,0,2)$) -- ($(1223)+(0,0,2)$)
-- ($(-alpha1)+(0,0,2)$) --($(-1223)+(0,0,2)$) -- cycle;
%\end{scope}
\end{tikzpicture}
\end{document}
我移动了 2 而不是 15,因为 15 真的很远,但你也可以这样做。