骑士巡游人物图

骑士巡游人物图

我正在将手写的课堂笔记转换为 LaTeX。有些图形我一直在使用 tikz 包。是否可以将下面代表马匹运动的图形转换为 LaTeX?骑士运动

答案1

另一种选择,基于\foreach带有一些移位和旋转的循环。

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}[scale=0.7]
% checkerboard, remove it if you want
\begin{scope}
  \clip (1.7,1.7) rectangle (7.3,7.3);
  \foreach\i in {1,2,3,4} \foreach\j in {1,...,7}
    \fill[gray!30] ({2*\i-1+mod(\j,2)},\j) rectangle++ (1,1);
\end{scope}
% axes
\foreach[count=\ii from 0]\i in {x,y}
  \draw[-latex,thick,shift={(-1,-1)},rotate=90*\ii] (1,0) --++ (9,0) 
   node[midway,shift={(-0.5*\ii,0.5*\ii-0.5)}] {$\i$};
% rectangles
\foreach\i in {0,4}
  \draw[thick] (\i,\i) rectangle (9-\i,9-\i);
% movements
\foreach\i in {0,90,180,270} \foreach\j in {-1,1}
  \draw[shift={(4.5,4.5)},rotate=\i] (0.5,0.25*\j) -|++ (1.5,0.75*\j)
   node[circle,fill,inner sep=0.5mm] {};
% (i,j)
\node at (7,-2.5) {$(i,j)$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

这可以作为一个起点:

\documentclass[tikz, margin=5pt]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
  , thick
  , box/.style = {
    , minimum width = #1
    , minimum height = #1
    , draw
  }
  , end/.style = {
    , draw
    , circle
    , minimum width = 2
    , fill = black
    , inner sep = 0
  }
  , arr/.style = {
    , -latex
  }
]
  \node (outer) [box = 100] {}; % a node named outer (of size 100x100)
  \node (inner) [box = 10] {};  % a node named inner (of size 10x10)
  \draw (inner.20) -| ++ (20pt, 10pt) node [end] {}; % from 20 degree of inner
  \draw (inner.-20) -| ++ (20pt, -10pt) node [end] {};
  \draw (inner.20+90) |- ++ (-10pt, 20pt) node [end] {};
  \draw (inner.-20+90) |- ++ (10pt, 20pt) node [end] {};
  \draw (inner.20-90) |- ++ (10pt, -20pt) node [end] {};
  \draw (inner.-20-90) |- ++ (-10pt, -20pt) node [end] {};
  \draw (inner.20+180) -| ++ (-20pt, -10pt) node [end] {};
  \draw (inner.-20+180) -| ++ (-20pt, +10pt) node [end] {};

  \draw [arr] ([yshift = -10]outer.south west) -- ([yshift = -10]outer.south east) node [midway, below] {$x$};
  \draw [arr] ([xshift = -10]outer.south west) -- ([xshift = -10]outer.north west) node [midway, left] {$y$};

  % use the positioning library
  \node [below right = 60pt and 30pt of inner] {$(i,j)$};
  
\end{tikzpicture}%
\end{document}

结果

相关内容