![如何旋转给定角度的正方形?](https://linux22.com/image/344814/%E5%A6%82%E4%BD%95%E6%97%8B%E8%BD%AC%E7%BB%99%E5%AE%9A%E8%A7%92%E5%BA%A6%E7%9A%84%E6%AD%A3%E6%96%B9%E5%BD%A2%EF%BC%9F.png)
我想要绕顶点 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}