附有代码,三角形 $PQR$ 的高脚从 $R$ 开始标记为 $G$。坐标是根据以下命令计算的。
\coordinate (G) at ($(P)!(R)!(Q)$);
我构造一个辅助点$V$以便绘制直角标记。
\coordinate (V) at ($(G)!3.75mm!-45:(P)$);
\draw ($(P)!(V)!(G)$) -- (V) -- ($(R)!(V)!(G)$);
对我来说,$G$ 处的直角标记看起来并不垂直于边。具体来说,它看起来并不垂直于边 $\overline{\mathit{GP}}$。这仅仅是视觉错觉吗?
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
%A triangle is drawn.
\coordinate (P) at (12,0);
\coordinate (Q) at ($(P) +(120:2/5*6)$);
\coordinate (R) at ($(Q) +({2/5*(-7.5)},0)$);
\draw (P) -- (Q) -- (R) -- cycle;
%The labels for the vertices are typeset.
\path let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in node[anchor={0.5*(\n1-60)+180}, inner sep=0] at ($(P) +({0.5*(\n1-60)}:0.15)$){$P$};
\path node[anchor=west, inner sep=0] at ($(Q) +(0.15,0)$){$Q$};
\path node[anchor=east, inner sep=0] at ($(R) +(-0.15,0)$){$R$};
%The foot of the altitude from R is located.
\coordinate (G) at ($(P)!(R)!(Q)$);
\node[anchor={0.5*(30+120)+180}, inner sep=0] at ($(G) +({0.5*(30+120)}:0.15)$){$G$};
%A right-angle mark is drawn at G.
\coordinate (V) at ($(G)!3.75mm!-45:(P)$);
\path[fill=yellow] ($(P)!(V)!(G)$) -- (V) -- ($(R)!(V)!(G)$) -- (G) -- cycle;
\draw ($(P)!(V)!(G)$) -- (V) -- ($(R)!(V)!(G)$);
\draw[dashed] (G) -- (Q);
\draw[dashed] (G) -- (R);
\draw[name path=arc_to_mark_angle_at_P,draw=blue] let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)}, \p2=($(P)-(R)$), \n2={atan(\y2/\x2)} in ($(P)!5mm!(Q)$) arc ({\n1-180}:{\n2-180}:0.5);
\draw[blue] let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)}, \p2=($(P)-(R)$), \n2={atan(\y2/\x2)} in ($(P) +({0.5*(\n1+\n2)-180}:{0.5cm-3pt})$) -- ($(P) +({0.5*(\n1+\n2)-180}:{0.5cm+3pt})$);
\end{tikzpicture}
\hspace{\fill}
\end{document}
答案1
该angles
库提供了两张图片(angle
和right angle
),我们可以用它们来标记角度,也可以在角落添加标签,而不必自己计算所有角度。
除了文字,我们还可以使用另一张图片(此处vert
)来标记角度。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{angles, calc}
\makeatletter
\tikzset{
pics/mark corner/.style args={#1--#2--#3}{
/tikz/angle radius=0pt, /tikz/angle eccentricity=0, /tikz/pic text={$#2$},
/tikz/pic text options={circle, inner sep=+.15em, anchor=.5*\tikz@start@angle@temp+.5*\tikz@end@angle@temp},
angle={#1--#2--#3}},
pics/mark angle with pic/.style={
/tikz/angle eccentricity=1,
/tikz/pic text options={pic, rotate=90+.5*\tikz@start@angle@temp+.5*\tikz@end@angle@temp},
angle={#1}}}
\makeatother
\tikzset{
pic/.is if=tikz@node@is@pic,
pics/vert/.style={% nested pics need care
setup code=, background code=, foreground code=,
code=\draw (down:1mm) -- (up:1mm);},
pics/right angle/.prefix style={/tikz/angle radius=2.65mm},%3.75mm/sqrt2
angle radius=5mm}
\begin{document}
\begin{tikzpicture}
\path (12,0) coordinate (P)
++(120:2/5*6) coordinate[label=right:$Q$] (Q)
++(-2/5*7.5,0) coordinate[label=left:$R$] (R)
coordinate (G) at ($(P)!(R)!(Q)$);
\foreach \c in {R--G--P, Q--P--R}
\pic {mark corner/.expanded=\c};
\pic[draw, fill=yellow] {right angle = R--G--P};
\pic[draw, blue, pic text=vert] {mark angle with pic = Q--P--R};
\draw (P) -- (Q) -- (R) -- cycle;
\draw[dashed] (Q) -- (G) -- (R);
\end{tikzpicture}
\end{document}
输出
答案2
根据我与 Jasper Habicht 的对话,很明显我的个人电脑上的 MikTex 无法准确编译某些命令。在这种情况下,定位($(P)!(V)!(G)$)
和的坐标的命令($(R)!(V)!(G)$)
并不完全正确。
我正在发布一个备用代码,用来在点 $G$ 处绘制直角标记。
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
%A triangle is drawn.
\coordinate (P) at (12,0);
\coordinate (Q) at ($(P) +(120:2/5*6)$);
\coordinate (R) at ($(Q) +({2/5*(-7.5)},0)$);
\draw (P) -- (Q) -- (R) -- cycle;
%The labels for the vertices are typeset.
\path let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in node[anchor={0.5*(\n1-60)+180}, inner sep=0] at ($(P) +({0.5*(\n1-60)}:0.15)$){$P$};
\path node[anchor=west, inner sep=0] at ($(Q) +(0.15,0)$){$Q$};
\path node[anchor=east, inner sep=0] at ($(R) +(-0.15,0)$){$R$};
%The foot of the altitude from R is located.
\coordinate (G) at ($(P)!(R)!(Q)$);
\node[anchor={0.5*(30+120)+180}, inner sep=0] at ($(G) +({0.5*(30+120)}:0.15)$){$G$};
%A right-angle mark is drawn at G.
\coordinate (V) at ($(G)!3.75mm!-45:(P)$);
%\path[fill=yellow] ($(P)!(V)!(G)$) -- (V) -- ($(R)!(V)!(G)$) -- (G) -- cycle;
%\draw ($(P)!(V)!(G)$) -- (V) -- ($(R)!(V)!(G)$);
\path[fill=red, rotate={120}] (V) rectangle (G);
\draw ($(P)!(V)!(G)$) -- (V) -- ($(R)!(V)!(G)$);
\path let \p1=($(G)-(R)$), \n1={atan(\y1/\x1)} in coordinate (V_1) at ($(V) +(\n1:1)$);
\path coordinate (V_2) at ($(V) +(120:1)$);
\coordinate (W_1) at (intersection of G--P and V--V_1);
\coordinate (W_2) at (intersection of G--R and V--V_2);
\path[fill=yellow] (W_1) -- (V) -- (W_2) -- (G) -- cycle;
\draw (W_1) -- (V) -- (W_2);
\draw[dashed] (G) -- (Q);
\draw[dashed] (G) -- (R);
\draw[name path=arc_to_mark_angle_at_P,draw=blue] let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)}, \p2=($(P)-(R)$), \n2={atan(\y2/\x2)} in ($(P)!5mm!(Q)$) arc ({\n1-180}:{\n2-180}:0.5);
\draw[blue] let \p1=($(P)-(Q)$), \n1={atan(\y1/\x1)}, \p2=($(P)-(R)$), \n2={atan(\y2/\x2)} in ($(P) +({0.5*(\n1+\n2)-180}:{0.5cm-3pt})$) -- ($(P) +({0.5*(\n1+\n2)-180}:{0.5cm+3pt})$);
\end{tikzpicture}
\hspace{\fill}
\end{document}