绘制矢量操作

绘制矢量操作

我想画这样的东西:

在此处输入图片描述 在此处输入图片描述

我需要显示很多此类操作的组合,所以我的问题是 - 有没有有效的方法来绘制这样的矢量操作?

答案1

这应该可以帮助你入门:

在此处输入图片描述

它使用蒂克兹。如果能更自动化一些就更好了……

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows}
\usetikzlibrary{positioning}
\begin{document}

  \tikzset{% define the style of the nodes for drawing the squares
     mysquare/.style ={shape=rectangle, draw=black!40,thick, top color=white,
                       bottom color=#1, drop shadow,
     }
  }
  \begin{tabular}{c@{\hspace*{20mm}}c}% put inside a table to compactify the image
  \begin{tikzpicture}
    \foreach \x in {0,...,3} {% loop over the three rows
       \node[mysquare=yellow!30] at (0,-\x) {$A_\x$};
       \node at (1,-\x) {$+$};
       \node[mysquare=green!40] at (2,-\x) {$B_\x$};
       \node at (3,-\x) {$=$};
       \node[mysquare=red!50] at (4,-\x) {$C_\x$};
    }
  \end{tikzpicture}
  &
  \begin{tikzpicture}% use positioning to put the boxes together
    \foreach \letter/\col/\x in {A/yellow!30/0, B/green!40/2, C/red!50/4} {
      \node[mysquare=\col] (\letter 0) at (\x,0){$\letter_0$};
      \node[below=-1pt of \letter 0,mysquare=\col] (\letter 1) {$\letter_1$};
      \node[below=-1pt of \letter 1,mysquare=\col] (\letter 2) {$\letter_2$};
      \node[below=-1pt of \letter 2,mysquare=\col] (\letter 3) {$\letter_3$};
    }
    \node at (1,-0.8) {$+$};% place + and = by hand
    \node at (3,-0.8) {$=$};
  \end{tikzpicture}
  \end{tabular}
\end{document}

答案2

这是一个(不太优雅的)PSTricks 解决方案,其宏语法如下:

\VectorOp[<index in bottom row>]{<number of rows>}

现在来看看代码和输出:

\documentclass{article}

\usepackage{mathtools}
\usepackage{multido}
\usepackage{pst-slpe}
\usepackage{xfp}

% parameters
\def\paraA{0.70}
\def\paraB{0.36}
\def\paraC{0.54}
\def\paraD{0.28}
% macros for structuring the code
\newcommand*\distA[2]{\fpeval{\paraA*(#1-1)+\paraB*#2}}
\newcommand*\distB[2]{\fpeval{(0.5*\paraC*(#2-1)+\paraD)*#1}}
% vector operations
\def\vectorOp[#1]#2{%
\begin{pspicture}(\distA{5}{2},\distB{2}{#2})
\psset{fillstyle = slope, slopeangle = 90, slopeend = white}
  \multido{\r = \paraD+\paraC, \i = #1+-1}{#2}{%
    \rput(\distA{1}{1},\r){\psframebox[slopebegin = yellow!50]{$A_{\i}$}}
    \rput(\distA{3}{1},\r){\psframebox[slopebegin = green!50]{$B_{\i}$}}
    \rput(\distA{5}{1},\r){\psframebox[slopebegin = orange]{$C_{\i}$}}}
  \rput(\distA{2}{1},\distB{1}{#2}){$+$}
  \rput(\distA{4}{1},\distB{1}{#2}){$=$}
\end{pspicture}}

\begin{document}

\begin{align*}
  &\vectorOp[0]{1}\\[0.5ex]
  &\vectorOp[1]{1}\\[0.5ex]
  &\vectorOp[2]{1}\\[0.5ex]
  &\vectorOp[3]{1}\\[4ex]
  &\vectorOp[3]{4}
\end{align*}

\end{document}

输出

相关内容