TikZ 中的旋转和平移变换如何进行?

TikZ 中的旋转和平移变换如何进行?

我是 TikZ 的新手,所以我正在阅读 TikZ 文档。第 43 页有一个如下所示的示例

\begin{tikzpicture}[even odd rule,x=10pt, y=10pt, scale=4]
    \filldraw[fill=yellow!80!black] (0,0) rectangle (1,1)
           [xshift=5pt, yshift=5pt] (0,0) rectangle (1,1)
                        [rotate=30] (-1,-1) rectangle (2,2);
\end{tikzpicture}

吸引

在此处输入图片描述

我理解小矩形是如何移动的。矩形的左下角向右移动了 0.5 个单位。

在此处输入图片描述

但我不知道大正方形的旋转是如何进行的。如果我们看下面的图
在此处输入图片描述

绿色方块是旋转前的原始方块(\draw (-1,-1) rectangle (2,2);),黑色倾斜的无填充方块是绿色方块旋转30度。如果我们将黑色未填充方块向每个轴的正方向移动5个单位,最底角应该在红色圆圈处,即(-0.5,-0.5)。但结果并没有像我描述的那样显示出来。和是如何工作shiftrotate

答案1

在此处输入图片描述

蒂克兹写成函数的数学组合形式,比如组成r并应用于A,即t(r(a)),首先应用写入过程中最后出现的函数。例如,r首先作用于A, 进而根据结果​​采取行动克(一)回到shift+旋转或者旋转+shift,结果取决于两个基本等距投影中的哪一个最后出现。

在问题的初始绘图中,对于上图 1 中的蓝色填充方块,旋转最后出现。因此,黑色方块相对于原点旋转,然后将结果与向量平移(2.8, 0.8)

评论每次旋转,无论其在\draw命令中的位置如何,都是相对于中心进行的(0,0)

在图 2 中,两个组合的等距投影被图形分解。

代码

\documentclass[11pt, a4paper]{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}

\tikzmath{%
  real \dx, \dy, \da, \r, \R;
  \dx = 2.8;
  \dy = .8;
  \da = -23;
  \r = {sqrt(2)}; 
}
\begin{figure}[htb!]
  \centering
  \begin{tikzpicture}[every node/.style={inner sep=.1cm, fill opacity=1},
    scale=.8]
    \draw[gray!50] (-2, -2) grid (5, 3);
    \draw[red, ->] (-3, 0) -- (6, 0);
    \draw[red, ->] (0, -3) -- (0, 4);
    
    \draw[very thick](-1, -1) rectangle ++(3, 3);

    \filldraw[fill=blue!90!green, fill opacity=.4]
    [xshift=\dx cm, yshift=\dy cm, rotate=\da]
    (-1, -1) rectangle (2, 2);
    
    \filldraw[fill=violet, fill opacity=.4]
    [rotate=\da, xshift=\dx cm, yshift=\dy cm]
    (-1, -1) rectangle (2, 2);
  \end{tikzpicture}
  \caption{The blue filled square is issued from the initial question.
    It is the result a rotation of angle $-22^\circ$ with respect to
    the center $(0, 0)$, and then of a translation with the vector
    $(2.8, .8)$.  The red filled square is the result of the
    translation and then the rotation operations applied on the same
    black non filled square.}
  \label{fig:1}
\end{figure}


\begin{figure}[htb!]
  \centering
  \begin{tikzpicture}[every node/.style={inner sep=.1cm, fill opacity=1},
    scale=.8]
    \draw[gray!50] (-2, -2) grid (5, 3);
    \draw[red, ->] (-3, 0) -- (6, 0);
    \draw[red, ->] (0, -3) -- (0, 4);
    
    \draw[very thick] (-1, -1) rectangle ++(3, 3);
    \filldraw[fill=blue!90!green, fill opacity=.1][rotate=\da]
    (-1, -1) rectangle ++(3, 3);
    
    \begin{scope}[xshift=\dx cm, yshift=\dy cm]
      \filldraw[fill=blue!90!green, fill opacity=.4][rotate=\da]
      (-1, -1) rectangle ++(3, 3);
    \end{scope}

    \draw (170: \r) arc (170: 250: \r);
  \end{tikzpicture}
  % 
  \begin{tikzpicture}[every node/.style={inner sep=.1cm, fill opacity=1},
    scale=.8]
    \draw[gray!50] (-2, -2) grid (5, 3);
    \draw[red, ->] (-3, 0) -- (6, 0);
    \draw[red, ->] (0, -3) -- (0, 4);
    
    \draw[very thick](-1, -1) rectangle ++(3, 3);
    
    \filldraw[fill=violet, fill opacity=.1]
    (-1+\dx , -1+\dy ) rectangle ++(3, 3);
    \filldraw[fill=violet, fill opacity=.4][rotate=\da]
    (-1+\dx , -1+\dy ) rectangle ++(3, 3);
  \end{tikzpicture}
  \caption{The two compositions form Figure 1 decomposed in elementary
    \texttt{TikZ} drawing commands.  In both cases, the center of
    rotation is the origin, the point $(0, 0)$.}
  \label{fig:2}
\end{figure}
\end{document}

相关内容