用TikZ的matrix库结合tkz-euclide宏包作了一个实现,代码不够优雅,希望大家一起讨论。
\documentclass{article}
\usepackage{tkz-euclide}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix}
% 将TikZ坐标名称转换为tkz坐标名称
\newcommand{\CopyPointToTKZ}[2]{%
\path (#1);
\pgfgetlastxy{\macrox}{\macroy}
\pgfmathsetmacro{\macroxcm}{\macrox/1cm}
\pgfmathsetmacro{\macroycm}{\macroy/1cm}
\tkzDefPoint(\macroxcm,\macroycm){#2}
}
\begin{document}
\begin{tikzpicture}
\node (d) at (0,0) {$D=$};
\matrix (m) [%
matrix of math nodes,
nodes in empty cells,
left delimiter=|,
right delimiter=|,
nodes={anchor=center,minimum size=2em},
right= 0.1 of d, % 应该使用相对坐标
] {%
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}\\
};
% \draw (m-1-1.center) rectangle (m-3-3.center);
% 将TikZ坐标标记转换为tkz坐标标记
\foreach \i in {1,2,...,3}{%
\foreach \j in {1,2,...,3}{%
\CopyPointToTKZ{m-\i-\j.center}{M_\i_\j}
}
}
% 定义主对角线方向的平行线及求各个交点
\foreach \i [count=\j from 4] in {2,3}{%
\tkzDefLine[parallel=through M_1_\i](M_1_1,M_3_3)
\tkzGetPoint{p}
\tkzInterLL(M_1_\i,p)(M_3_1,M_3_3)
\tkzGetPoint{M_3_\j}
}
\foreach \i [count=\j from 4, count=\k from 3] in {3,2}{%
\tkzDefLine[parallel=through M_\i_1](M_1_1,M_3_3)
\tkzGetPoint{p}
\tkzDefLine[parallel=through M_3_\j](M_3_1,M_1_3)
\tkzGetPoint{q}
\tkzInterLL(M_3_\j,q)(M_\i_1,p)
\tkzGetPoint{M_4_\k}
}
% 定义副对角线方向的平行线及求各个交点
\foreach \i [count=\j from 6] in {1,2}{%
\tkzDefLine[parallel=through M_1_\i](M_3_1,M_1_3)
\tkzGetPoint{p}
\tkzInterLL(M_1_\i,p)(M_3_1,M_3_3)
\tkzGetPoint{M_3_\j}
}
\foreach \i [count=\j from 6, count=\k from 1] in {2,3}{%
\tkzDefLine[parallel=through M_\i_3](M_3_1,M_1_3)
\tkzGetPoint{p}
\tkzDefLine[parallel=through M_3_\j](M_1_1,M_3_3)
\tkzGetPoint{q}
\tkzInterLL(M_3_\j,q)(M_\i_3,p)
\tkzGetPoint{M_4_\k}
}
% 绘制主对角线方向
\foreach \i [count=\j from 3] in {1,2,3}{%
\tkzDrawSegment[thick, red](M_1_\i,M_3_\j)
}
\foreach \i [count=\j from 3] in {3,2}{%
\tkzDrawSegment[thick, red](M_\i_1,M_4_\j)
}
\foreach \i [count=\j from 3] in {4,5}{%
\tkzDrawSegment[thick, red](M_3_\i,M_4_\j)
}
% 绘制副对角线方向
\foreach \i [count=\j from 6] in {1,2}{%
\tkzDrawSegment[thick, blue, dashed](M_1_\i,M_3_\j)
}
\tkzDrawSegment[thick, blue, dashed](M_1_3,M_3_1)
\foreach \i [count=\j from 1] in {2,3}{%
\tkzDrawSegment[thick, blue, dashed](M_\i_3,M_4_\j)
}
\foreach \i [count=\j from 1] in {6,7}{%
\tkzDrawSegment[thick, blue, dashed](M_3_\i,M_4_\j)
}
\end{tikzpicture}
\end{document}
实现结果如下:
问 三阶行列式计算图解如何画?