我在 LaTeX 中编写了代码:
\begin{tikzpicture}
\draw (-1.81,-1.81) rectangle (1.81,1.81);
\draw[rotate around={134:(0,0)}] (-1.5,1.06) rectangle (1.5,-1.06);
\end{tikzpicture}
外边正方形的名称如何写成ABCD,内边倾斜矩形的名称如何写成EFGH?谢谢。
答案1
以下示例命名坐标并为其添加标签:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw
(-1.81,-1.81) coordinate (A)
rectangle (1.81,1.81) coordinate (C)
(A -| C) coordinate (B)
(A |- C) coordinate (D)
;
\draw[rotate around={134:(0,0)}]
(-1.5,1.06) coordinate (E)
rectangle (1.5,-1.06) coordinate (G)
(E |- G) coordinate (F)
(E -| G) coordinate (H)
;
\path
(A) node[below left] {A}
(B) node[below right] {B}
(C) node[above right] {C}
(D) node[above left] {D}
(E) node[below] {E}
(F) node[right] {F}
(G) node[above] {G}
(H) node[left] {H}
;
\end{tikzpicture}
\end{document}
一些微调:
- 可以计算出角度,结果约为 135.05°,而不是 134°。
- 如果应避免内部矩形的突出角,则
miter limit=1
在此处剪切或提供帮助。
例子:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro\angle{
90
+ atan(1.06/1.5)
+ acos(1.81 / sqrt(1.5*1.5 + 1.06*1.06))
}
\typeout{Rotation angle: \angle}
\draw
(-1.81,-1.81) coordinate (A)
rectangle (1.81,1.81) coordinate (C)
(A -| C) coordinate (B)
(A |- C) coordinate (D)
;
\draw[rotate around={\angle:(0,0)}, miter limit=1]
(-1.5,1.06) coordinate (E)
rectangle (1.5,-1.06) coordinate (G)
(E |- G) coordinate (F)
(E -| G) coordinate (H)
;
\path
(A) node[below left] {A}
(B) node[below right] {B}
(C) node[above right] {C}
(D) node[above left] {D}
(E) node[below] {E}
(F) node[right] {F}
(G) node[above] {G}
(H) node[left] {H}
;
\end{tikzpicture}
\end{document}