答案1
有了库,这一切都变得非常简单calc
,您可以使用语法检索坐标let ... in
,并使用它atan2
计算角度和veclen
计算可在极坐标中使用的长度。以下a
是正方形的尺寸以及b
Q 和 D 之间的水平距离。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[declare function={a=4;b=1;}]
\draw (0,a) coordinate[label=above:$A$] (A) --
(a,a) coordinate[label=above:$B$] (B) --
(a,0) coordinate[label=below:$C$] (C) --
(0,0) coordinate[label=below:$D$] (D) -- cycle;
\path (b,0) coordinate[label=below:$Q$] (Q)
let \p1=($(Q)-(A)$),\n1={atan2(\y1,\x1)+45} in
($(A)+(\n1:1)$) coordinate (aux)
(intersection cs:first line={(C)--(B)},second line={(A)--(aux)})
coordinate[label=right:$P$] (P)
let \p2=($(P)-(A)$),\n2={atan2(\y2,\x2)-90},\n3={veclen(\x2,\y2)}
in ($(A)+(\n2:\n3)$) coordinate[label=below:$P'$] (P');
\draw [blue] (Q) -- (A) -- (P) -- (P');
\fill foreach \X in {A,B,C,D,P,P',Q} {(\X) circle[radius=1.5pt] };
\end{tikzpicture}
\end{document}
当然,你可以改变b。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\foreach \X in {0.2,0.25,...,2,1.95,1.9,...,0.25}
{\begin{tikzpicture}[declare function={a=4;b=\X;}]
\path[use as bounding box] (-a,-0.5) rectangle (a+0.5,a+0.5);
\draw (0,a) coordinate[label=above:$A$] (A) --
(a,a) coordinate[label=above:$B$] (B) --
(a,0) coordinate[label=below:$C$] (C) --
(0,0) coordinate[label=below:$D$] (D) -- cycle;
\path (b,0) coordinate[label=below:$Q$] (Q)
let \p1=($(Q)-(A)$),\n1={atan2(\y1,\x1)+45} in
($(A)+(\n1:1)$) coordinate (aux)
(intersection cs:first line={(C)--(B)},second line={(A)--(aux)})
coordinate[label=right:$P$] (P)
let \p2=($(P)-(A)$),\n2={atan2(\y2,\x2)-90},\n3={veclen(\x2,\y2)}
in ($(A)+(\n2:\n3)$) coordinate[label=below:$P'$] (P');
\draw [blue] (Q) -- (A) -- (P) -- (P');
\fill foreach \X in {A,B,C,D,P,P',Q} {(\X) circle[radius=1.5pt] };
\end{tikzpicture}}
\end{document}
答案2
使用 tkz-euclide v1.16 或 2.40 beta这里
\documentclass[tikz, border=1cm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmax = 8]
\tkzDefPoint(8,0){C}
\tkzDefPoint(0,0){D}
\tkzDefSquare(D,C)
\tkzGetPoints{B}{A}
\tkzDrawSquare(D,C)
\tkzGetRandPointOn[segment = C--D]{Q}
\tkzDefPointBy[rotation= center A angle 45](Q)
\tkzGetPoint{p}
\tkzInterLL(A,p)(C,B) \tkzGetPoint{P}
\tkzDefPointBy[rotation= center A angle -90](P)
\tkzGetPoint{P'}
\tkzDrawPoints(A,B,C,D,Q,P,P')
\tkzLabelPoints(A,B,C,D,Q,P,P')
\tkzDrawSegments(A,Q A,P P,P' D,P')
\tkzLabelAngle[pos = 1.5](Q,A,P){$45^{\circ}$}
\tkzMarkAngle[size = 1.8,mark = none,arc=l](Q,A,P)
\end{tikzpicture}
\end{document}