如何旋转给定角度的正方形?

如何旋转给定角度的正方形?

我想要绕顶点 B 90 度旋转一个正方形。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[thick] (0,0) rectangle (4,4);
\draw[thick] (0,4)--(1,2.6)--(4,0);
\draw[thick](0,0)--(1,2.6);
\node at (-0.3,0) {A};
\node at (4.3,0) {B};
\node at (4.3,4) {C};
\node at (-0.3,4) {D};
\node at (1.8,3) {P};
\node at (0,0) {$\bullet$};
\node at (0,4) {$\bullet$};
\node at (4,0) {$\bullet$};
\node at (1,2.6) {$\bullet$};
\node at (4,4) {$\bullet$};
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

答案1

绕一点旋转

\documentclass[tikz,border=10pt,multi]{standalone}
\begin{document}
\begin{tikzpicture}
  [
    my dot/.style={circle, inner sep=1pt, draw, fill, label=#1},
  ]
  \draw [thick, blue] (0,0) node (A) [my dot=left:A] {} |- (4,4) node (D) [midway, my dot=left:D] {} node (C) [my dot=right:C] {} |-   node (B) [midway, my dot=right:B] {} cycle (D) --  (1,2.6) node (P) [my dot=P] {} edge (A) -- (B);
  \foreach \i [count=\j, evaluate=\i as \k using {10*\i/35}] in {10,20,...,350}
  {
    \begin{scope}[rotate around={\i:(B)}]
      \draw [thick, blue!\k!magenta] (0,0) node (A\j) [my dot=left:A] {} |- (4,4) node (D\j) [midway, my dot=left:D] {} node (C\j) [my dot=right:C] {} |-   node (B\j) [midway, my dot=right:B] {} cycle (D\j) --  (1,2.6) node (P\j) [my dot=P] {} edge (A\j) -- (B\j);
    \end{scope}
  }
\end{tikzpicture}
\end{document}

相关内容