我可以将正方形围绕其中心旋转 90 度。
\documentclass{article}
\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,-0.3) {A};
\node at (4,-0.3) {B};
\node at (4,4.3) {C};
\node at (0,4.3) {D};
\node at (1.5,2.6) {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}
\begin{tikzpicture}[rotate around={90:(2,2)}]
\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.5,2.6) {Q};
\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
pic
这是一个使用以及 tikz 的标记节点机制的解决方案。
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\tikzset{point/.style={circle,fill,minimum width=1.5mm,inner sep=0mm},
myrectangle/.pic=
{\node[point] (A) at (0,0) {};
\node[point] (B) at (4,0) {};
\node[point] (C) at (4,4) {};
\node[point] (D) at (0,4) {};
\node[point] (P) at (1,2.6) {};
\draw[thick]
(A) -- (B) -- (C) -- (D) -- (A) -- (P)
(B) -- (P) -- (D);
}
}
\begin{tikzpicture}
\pic (R1) {myrectangle};
\pic[rotate around={90:(0,0)}] (R2) {myrectangle};
\draw[dotted] (R1P) -- (R2P);
\node[label=below:{$A'=A$}] at (R1A) {};
\node[label=below:$B$] at (R1B) {};
\node[label=above:$C$] at (R1C) {};
\node[label=above:{$B'=D$}] at (R1D) {};
\node[label=right:$P$] at (R1P) {};
\node[label=above:$C'$] at (R2C) {};
\node[label=below:$D'$] at (R2D) {};
\node[label=above:$P'$] at (R2P) {};
\end{tikzpicture}
\end{document}
答案2
如果要实现第二幅图像,只需移动第二幅tikzpicture
到第一个,并将其放在里面scope
,给予范围旋转选项加上移动选项,使其与另一个并排:
还改进了绘图代码,因为它重复性极强,而且使用 Ti钾Z 标签和样式可以使代码更加简洁。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}[bullet/.style={insert path={node[minimum size=4pt,inner sep=0pt,fill,circle, label={#1}]{}}}]
\draw[thick] (0,0) [bullet=below:A] -- (0,4) [bullet=above:D] -- (4,4) [bullet=above:C] -- (4,0) [bullet=below:B] -- cycle;
\draw[thick] (0,4) -- (1,2.6) [bullet=above right:P] -- (4,0) (0,0) -- (1,2.6) coordinate (P);
\begin{scope}[rotate around={90:(2,2)}, yshift=4cm]
\draw[thick] (0,0) [bullet=below:A] -- (0,4) [bullet=below:D] -- (4,4) [bullet=above:C] -- (4,0) [bullet=above:B] -- cycle;
\draw[thick] (0,4) -- (1,2.6) [bullet=above left:Q] -- (4,0) (0,0) -- (1,2.6) coordinate (Q);
\end{scope}
\draw[dotted] (P) -- (Q);
\end{tikzpicture}
\end{center}
\end{document}