如何绘制带有相交线的二维正方形?

如何绘制带有相交线的二维正方形?

我正在尝试绘制此精确图像(附件)

图像的具体属性:

  - angle QAP = 45 degrees (labeled theta)
  - ABCD is a square
  - P' is the 90 degree rotation of P along A (lying on CD)
  - Q and P can be anywhere in the lines BC and CD respectively 
  - AQ is the perpendicular bisector (cuts the middle) of line PP'

非常感谢你的帮助。最近才开始学习这些东西。

在此处输入图片描述

答案1

有了库,这一切都变得非常简单calc,您可以使用语法检索坐标let ... in,并使用它atan2计算角度和veclen计算可在极坐标中使用的长度。以下a是正方形的尺寸以及bQ 和 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}

在此处输入图片描述

相关内容