我正在写一篇科学文献,其中有一个部分涉及张量。
我花了一些时间使用 TikZ 尝试复制下面的图像,但没有成功。据我所知,我尝试使用一个基本“正方形”进行的任何旋转都会变形。我可能没有理解 TikZ 如何处理透视,但甚至无法使顶部和底部正确旋转,我放弃了。
这里有没有 LaTeX/TikZ 专家愿意向我展示如何操作?
答案1
这是一个开始。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta}
\begin{document}
\tdplotsetmaincoords{70}{150}
\begin{tikzpicture}[tdplot_main_coords,line cap=round,line join=round,
thick,>=Stealth,pics/dreibein/.style={code={%
\foreach \XX [count=\YY from 0] in {#1}
{
\draw[->] (0,0,0) -- ($\XX1*(\dreibein\YY)$)
node[above,dreibein/label]{$\sigma_{\pgfkeysvalueof{/tikz/dreibein/d}
\the\numexpr\YY+1}$};}
}},dreibein/.cd,label/.style={},d/.initial={}]
\draw[->] (0,0,0) coordinate (O) -- (4,0,0) node[above]{$x_1$};
\draw[->] (O) -- (0,6,0) node[above]{$x_2$};
\draw[->] (O) -- (0,0,6) node[left]{$x_3$};
\def\dreibein#1{\ifcase#1
{1,0,0}\or{0,1,0}\or{0,0,1}\fi}
\def\lstcols{"red","yellow","orange"}
\begin{scope}[shift={(0,4,4)}]
\foreach \X [evaluate=\X as \Y using {int(Mod(\X+1,3))},
evaluate=\X as \Z using {int(Mod(\X+2,3))}]in {0,1,2}
{\path ($-2*(\dreibein\X)$) pic[dreibein/label/.style={opacity=0}]{dreibein={-,-,-}};
\pgfmathsetmacro{\mycolor}{{\lstcols}[\X]}
\draw[fill=\mycolor,fill opacity=0.2] ($-2*(\dreibein\X)+2*(\dreibein\Y)+2*(\dreibein\Z)$)
-- ($-2*(\dreibein\X)+2*(\dreibein\Y)-2*(\dreibein\Z)$)
-- ($-2*(\dreibein\X)-2*(\dreibein\Y)-2*(\dreibein\Z)$)
-- ($-2*(\dreibein\X)-2*(\dreibein\Y)+2*(\dreibein\Z)$) -- cycle;
}
\foreach \X [evaluate=\X as \Y using {int(Mod(\X+1,3))},
evaluate=\X as \Z using {int(Mod(\X+2,3))}]in {0,1,2}
{\pgfmathsetmacro{\mycolor}{{\lstcols}[\X]}
\draw[fill=\mycolor,fill opacity=0.4] ($2*(\dreibein\X)+2*(\dreibein\Y)+2*(\dreibein\Z)$)
-- ($2*(\dreibein\X)+2*(\dreibein\Y)-2*(\dreibein\Z)$)
-- ($2*(\dreibein\X)-2*(\dreibein\Y)-2*(\dreibein\Z)$)
-- ($2*(\dreibein\X)-2*(\dreibein\Y)+2*(\dreibein\Z)$) -- cycle;
\path ($2*(\dreibein\X)$) pic[dreibein/d=\the\numexpr\X+1]{dreibein={+,+,+}};
}
\end{scope}
\end{tikzpicture}
\end{document}