我怎样才能绘制那些连接矩阵的线

我怎样才能绘制那些连接矩阵的线

我正在尝试绘制这样的东西:

在此处输入图片描述

我已经正常创建了矩阵,从这里

\begin{bmatrix}
x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
\hdotsfor{5} \\
x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
\end{bmatrix}

但它并没有给人 3D 的感觉,我怎样才能在这些矩阵之间创建这些线。

答案1

欢迎!您可以使用安装Ti 的tikz-3dplot视图和库3dZ 会自动加载,将矩阵投影到一些平面上。

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{65}{60}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[canvas is xz plane at y=2,transform shape]
 \node[inner xsep=-3pt,inner ysep=-0.3pt] (mat1){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} \\
  x_{21}       & x_{22}  \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \node[inner xsep=-4pt,inner ysep=-0.3pt] (mat2){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
  x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
  \hdotsfor{5} \\
  x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
  \end{bmatrix}$};
\end{scope}
\foreach \Y in {south,north} {\foreach \X in {west,east}
{\draw (mat1.\Y\space\X)  -- (mat2.\Y\space\X);}}
\end{tikzpicture}
\end{document}

在此处输入图片描述

还可以安装背景图案。

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds}
\begin{document}
\tdplotsetmaincoords{65}{60}
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[canvas is xz plane at y=2,transform shape]
 \node[inner xsep=-3pt,inner ysep=-0.3pt] (mat1){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} \\
  x_{21}       & x_{22}  \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \node[inner xsep=-4pt,inner ysep=-0.3pt] (mat2){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} & x_{13} & x_{14} \\
  x_{21}       & x_{22} & x_{23} & x_{24} \\
  x_{31}       & x_{32} & x_{33} & x_{34} \\
  x_{41}       & x_{42} & x_{43} & x_{44} \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[on background layer]
 \foreach \Y in {south,north} {\foreach \X in {west,east}
 {\draw (mat1.\Y\space\X)  -- (mat2.\Y\space\X);}}
 \foreach \X in {1,2}
 {\fill[blue!20] (mat\X.west)  -- (mat\X.east) -- (mat\X.south east) 
  -- (mat\X.south) -- (mat\X.north) -- (mat\X.north west) -- cycle; }
\end{scope} 
\end{tikzpicture}
\end{document}

在此处输入图片描述

您似乎在安装时遇到了问题tikz-3dplot。虽然应该没有问题,但这里有一个可能的解决方法。保存这个文件tikzlibrary3dtools.code.tex您正在编译的文件位于同一目录中。那么这也应该有效:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{backgrounds,3d,3dtools}
\begin{document}
\begin{tikzpicture}[3d/install view={phi=70,psi=0,theta=70}]
\begin{scope}[canvas is xz plane at y=2,transform shape]
 \node[inner xsep=-3pt,inner ysep=-0.3pt] (mat1){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} \\
  x_{21}       & x_{22}  \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[canvas is xz plane at y=0,transform shape]
 \node[inner xsep=-4pt,inner ysep=-0.3pt] (mat2){$\displaystyle
  \begin{bmatrix}
  x_{11}       & x_{12} & x_{13} & x_{14} \\
  x_{21}       & x_{22} & x_{23} & x_{24} \\
  x_{31}       & x_{32} & x_{33} & x_{34} \\
  x_{41}       & x_{42} & x_{43} & x_{44} \\
  \end{bmatrix}$};
\end{scope}
%
\begin{scope}[on background layer]
 \foreach \Y in {south,north} {\foreach \X in {west,east}
 {\draw (mat1.\Y\space\X)  -- (mat2.\Y\space\X);}}
 \foreach \X in {1,2}
 {\fill[blue!20] (mat\X.west)  -- (mat\X.east) -- (mat\X.south east) 
  -- (mat\X.south) -- (mat\X.north) -- (mat\X.north west) -- cycle; }
\end{scope} 
\end{tikzpicture}
\end{document}

请注意,角度的约定可能会在将来的库修订版中发生变化。问题是不同的软件包遵循不同的约定,例如tikz-3dplotpgfplots。目前尚不清楚“最佳”约定是什么。然而,在这些约定之间进行转换是一件痛苦的事。

相关内容