我有$\triangle{ABC}$
一条$\ell$
通过三角形两边中点的线。 $\ell$
平行于$\overline{BC}$
。在代码的最后几行中,我试图绘制另一条k
通过A
平行于 $\ell$
和 的线$\overline{BC}$
。我想k
在上面延伸$\overline{AC}$
相同的量$\ell$
。我尝试使用以下命令。
\draw[dashed, green] let \p1=($(upper_left_arrowhead)-(A)$), \n1={atan(\y1/\x1)} in (A) -- ($(A) +(\n1:{veclen(\x1,\y1)})$);
在我看来,我不能在命令中同时使用\n1={atan(\y1/\x1)}
和。veclen(\x1,\y1)
\draw
代码可以编译,因为我把它放在了%
最后三行的前面。
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}
%The vertices of a triangle are located.
\coordinate (A) at (0,0);
\coordinate (B) at (20:7);
\coordinate (C) at ($(B) +(150:3)$);
\draw (A) -- (B) -- (C) -- cycle;
%The midpoint of AB is called P.
\coordinate (P) at ($(A)!0.5!(B)$);
\path[name path=the_part_of_ell_through_AB] let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in (P) -- ($(P) +(\n1:2.5)$);
\path[name path=the_part_of_ell_through_AC] let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in (P) -- ($(P) +({\n1+180}:4)$);
%The arrowheads of line $\ell$ are to be drawn at the intersections of the horizontal and
%vertical lines through A.
\path[name path=the_vertical_line_through_A] (A) -- ($(A) +(0,3.5)$);
\path[name path=the_horizontal_line_through_A] (A) -- ($(A) +(6,0)$);
\coordinate[name intersections={of=the_part_of_ell_through_AC and the_vertical_line_through_A, by=upper_left_arrowhead}];
\coordinate[name intersections={of=the_part_of_ell_through_AB and the_horizontal_line_through_A, by=lower_right_arrowhead}];
\draw[latex-latex] (upper_left_arrowhead) -- (lower_right_arrowhead);
\draw let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in node[anchor={\n1+180}, inner sep=0] at ($(lower_right_arrowhead) + (\n1:0.15)$){$\ell$};
%Sides $\overline{AP}$ and $\overline{BP}$ are marked with "|".
\draw ($($(A)!0.5!(P)$)!3pt!90:(P)$) -- ($($(A)!0.5!(P)$)!3pt!-90:(P)$);
\draw ($($(B)!0.5!(P)$)!3pt!90:(P)$) -- ($($(B)!0.5!(P)$)!3pt!-90:(P)$);
%The labels for the vertices of the triangle are typeset.
\draw let \p1=($(A)-(B)$), \n1={atan(\y1/\x1)}, \p2=($(A)-(C)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+\n2)}, inner sep=0] at ($(A) + ({0.5*(\n1+\n2)+180}:0.15)$){$A$};
\draw let \p1=($(B)-(A)$), \n1={atan(\y1/\x1)}, \p2=($(B)-(C)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1+\n2)+180}, inner sep=0] at ($(B) + ({0.5*(\n1+\n2)}:0.15)$){$B$};
\draw let \p1=($(C)-(B)$), \n1={atan(\y1/\x1)}, \p2=($(C)-(A)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1-180+\n2)}, inner sep=0] at ($(C) + ({0.5*(\n1-180+\n2)+180}:0.15)$){$C$};
%The label for the midpoint of AB is typeset.
\draw let \p1=($(B)-(A)$), \n1={atan(\y1/\x1)}, \p2=($(B)-(C)$), \n2={atan(\y2/\x2)} in node[anchor={0.5*(\n1-180+\n2)+180}, inner sep=0] at ($(P) + ({0.5*(\n1-180+\n2)}:0.15)$){$P$};
%A line k is drawn through A that is parallel to BC. k is to extend above side AC as much as $\ell$ does,
%and k is to extend below side AB as much as $\ell$ does.
%\draw[dashed, green] let \p1=($(upper_left_arrowhead)-(A)$) in (A) -- ($(A) +({atan(\y1/\x1)}:{veclen(\x1,\y1)})$);
%\draw[dashed, green] let \p1=($(upper_left_arrowhead)-(A)$), \n1={atan(\y1/\x1)} in (A) -- ($(A) +(\n1:{veclen(\x1,\y1)})$);
%\draw[dashed] let \p1=($(lower_right_arrowhead)-(A)$), \n1={atan(\y1/\x1)} in (A) -- ($(A) +({atan(\y1/\x1)}:{veclen(\x1,\y1)})$);
\end{tikzpicture}
\end{document}
答案1
问题是(upper_left_arrowhead)
直接位于 上方(A)
。因此,\x1
等于零,因此\y1/\x1
无法计算。TeX 会在控制台上告诉您这一点。它与 无关veclen
。编译还没有进行到这一步。
我有点不明白你为什么要用看起来不必要的复杂方式做事。例如,为什么要用这样的方式标记顶点和中点?
为什么不只是,例如
\coordinate [label=below left:$A$] (A) at (0,0);
\coordinate [label=right:$B$] (B) at (20:7);
\coordinate [label=above:$C$] (C) at ($(B) +(150:3)$);
...
\coordinate [label=below:$P$] (P) at ($(A)!0.5!(B)$);
\path[name path=the_part_of_ell_through_AB] let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in (P) -- ($(P) +(\n1:2.5)$) node {$\ell$};
据我所知,它的作用基本上是相同的?
我认为对于新路径,您需要类似以下内容的内容。
改变线条的绘制升这样路径就被命名为upper path
:
\draw[latex-latex,name path=upper path] (upper_left_arrowhead) -- (lower_right_arrowhead);
现在命名一条路径A到C:
\path [name path=ac] (A) -- (C);
并得到这些线的交点:
\coordinate [name intersections={of=upper path and ac, by=intersect}];
然后画出相关部分升移动,以便它们相对于A而不是升和AB和交流:
\draw [dashed, green] ($(upper_left_arrowhead)-(intersect)$) -- ($(lower_right_arrowhead)-(P)$);
完整代码:
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}
%The vertices of a triangle are located.
\coordinate [label=below left:$A$] (A) at (0,0);
\coordinate [label=right:$B$] (B) at (20:7);
\coordinate [label=above:$C$] (C) at ($(B) +(150:3)$);
\draw (A) -- (B) -- (C) -- cycle;
%The midpoint of AB is called P.
\coordinate [label=below:$P$] (P) at ($(A)!0.5!(B)$);
\path[name path=the_part_of_ell_through_AB] let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in (P) -- ($(P) +(\n1:2.5)$) node {$\ell$};
\path[name path=the_part_of_ell_through_AC] let \p1=($(B)-(C)$), \n1={atan(\y1/\x1)} in (P) -- ($(P) +({\n1+180}:4)$);
%The arrowheads of line $\ell$ are to be drawn at the intersections of the horizontal and
%vertical lines through A.
\path[name path=the_vertical_line_through_A] (A) -- ($(A) +(0,3.5)$);
\path[name path=the_horizontal_line_through_A] (A) -- ($(A) +(6,0)$);
\coordinate[name intersections={of=the_part_of_ell_through_AC and the_vertical_line_through_A, by=upper_left_arrowhead}];
\coordinate[name intersections={of=the_part_of_ell_through_AB and the_horizontal_line_through_A, by=lower_right_arrowhead}];
\draw[latex-latex,name path=upper path] (upper_left_arrowhead) -- (lower_right_arrowhead);
%Sides $\overline{AP}$ and $\overline{BP}$ are marked with "|".
\draw ($($(A)!0.5!(P)$)!3pt!90:(P)$) -- ($($(A)!0.5!(P)$)!3pt!-90:(P)$);
\draw ($($(B)!0.5!(P)$)!3pt!90:(P)$) -- ($($(B)!0.5!(P)$)!3pt!-90:(P)$);
\path [name path=ac] (A) -- (C);
\coordinate [name intersections={of=upper path and ac, by=intersect}];
\draw [dashed, green] ($(upper_left_arrowhead)-(intersect)$) -- ($(lower_right_arrowhead)-(P)$);
\end{tikzpicture}
\end{document}