我稍后需要 Y 和 Z 之间的长度。我希望这能起作用,但没有。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Koordinaten
\coordinate (A) at (1,-3);
\coordinate (B) at (8,1);
\coordinate (C) at (1,0);
\coordinate (D) at (8,4);
\coordinate (E) at (6,-4);
\coordinate (F) at (6,4);
% Strecken
\draw[line width=1.5pt, name path = a] (A) -- node[midway, below right]{a} (B);
\draw[line width=1.5pt,name path = b] (C) -- node[midway, below right] {b} (D);
\draw[line width=1.5pt,name path = c] (E) -- node[near end, right] {c} (F);
% Finde die Schnittpunkte
% a und c
\path[name intersections={of=a and c, by={Z}}];
% b und c
\path[name intersections={of=b and c, by={Y}}];
% Berechne die Länge der Strecke YZ
\pgfmathveclen{\x1}{\y1}
\edef\lengthZY{\pgfmathresult}
% Ausgabe der Länge
\draw (Y) -- (Z) node[midway, above] {\(\lengthZY\)};
\end{tikzpicture}
\end{document}
谢谢你的帮助帕特里克
答案1
您的代码无法编译,您需要 tikz 库intersections
和calc
。
\usetikzlibrary{intersections, calc}
此外,\x1
和\y1
由路径操作定义let
。这应该有效:
\draw let \p1=(Y), \p2=(Z), \n1 = {veclen(\x2-\x1,\y2-\y1)} in
(Y) -- (Z) node[midway, above] {\n1};
完整代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, calc}
\begin{document}
\begin{tikzpicture}
% Koordinaten
\coordinate (A) at (1,-3);
\coordinate (B) at (8,1);
\coordinate (C) at (1,0);
\coordinate (D) at (8,4);
\coordinate (E) at (6,-4);
\coordinate (F) at (6,4);
% Strecken
\draw[line width=1.5pt, name path = a] (A) -- node[midway, below right]{a} (B);
\draw[line width=1.5pt,name path = b] (C) -- node[midway, below right] {b} (D);
\draw[line width=1.5pt,name path = c] (E) -- node[near end, right] {c} (F);
% Finde die Schnittpunkte
% a und c
\path[name intersections={of=a and c, by={Z}}];
% b und c
\path[name intersections={of=b and c, by={Y}}];
% Berechne die Länge der Strecke YZ
% Ausgabe der Länge
\draw let \p1=(Y), \p2=(Z), \n1 = {veclen(\x2-\x1,\y2-\y1)} in
(Y) -- (Z) node[midway, above] {\n1};
\end{tikzpicture}
\end{document}
答案2
在pgfmanual
文档第 4.1.3 节“围绕 A 的圆”中,我们可以读到:
剩下的唯一问题是获取向量 AB 的 x 和 y 坐标。为此,我们需要一个新概念:let 操作
我们可以像 jlab 那样使用 2 个点\p1
和\p2
,我们也可以使用向量\p1
(YZ) 并使用\pgfmathveclen
如您的帖子中所示。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\begin{document}
\begin{tikzpicture}
% Koordinaten
\coordinate (A) at (1,-3);
\coordinate (B) at (8,1);
\coordinate (C) at (1,0);
\coordinate (D) at (8,4);
\coordinate (E) at (6,-4);
\coordinate (F) at (6,4);
% Strecken
\draw[line width=1.5pt, name path = a] (A) -- node[midway, below right]{a} (B);
\draw[line width=1.5pt,name path = b] (C) -- node[midway, below right] {b} (D);
\draw[line width=1.5pt,name path = c] (E) -- node[near end, right] {c} (F);
% Finde die Schnittpunkte
% a und c
\path[name intersections={of=a and c, by={Z}}];
% b und c
\path[name intersections={of=b and c, by={Y}}];
% Ausgabe der Länge
\draw (Y) -- (Z) let
\p1=($(Z) - (Y)$)
in
node[midway,right] {$\pgfmathveclen{\x1}{\y1}\pgfmathresult$};
\end{tikzpicture}
\end{document}
编辑:随包裹一起tkz-euclide
\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
% Koordinaten
\tkzDefPoints{1/-3/A,8/1/B,1/0/C,8/4/D,6/-4/E,6/4/F}
% \coordinate (A) at (1,-3);
% \coordinate (B) at (8,1);
% \coordinate (C) at (1,0);
% \coordinate (D) at (8,4);
% \coordinate (E) at (6,-4);
% \coordinate (F) at (6,4);
% Strecken
\tkzDrawLines[line width=1.5pt](A,B C,D E,F)
\tkzLabelLine[pos=0.3,below right](A,B){$a$}
\tkzLabelLine[pos=0.3,below right](C,D){$b$}
\tkzLabelLine[pos=1.1,below right](E,F){$c$}
% \draw[line width=1.5pt, name path = a] (A) -- node[midway, below right]{a} (B);
% \draw[line width=1.5pt,name path = b] (C) -- node[midway, below right] {b} (D);
% \draw[line width=1.5pt,name path = c] (E) -- node[near end, right] {c} (F);
% Finde die Schnittpunkte
% a und c
\tkzInterLL(A,B)(E,F) \tkzGetPoint{Z}
% \path[name intersections={of=a and c, by={Z}}];
% % b und c
\tkzInterLL(C,D)(E,F) \tkzGetPoint{Y}
%\tkzLabelPoints(A,...,F,Z,Y)
% \path[name intersections={of=b and c, by={Y}}];
% Ausgabe der Länge
\tkzCalcLength(Y,Z)\tkzGetLength{YZ}
\tkzLabelSegment[right](Y,Z){$\pgfmathprintnumber{\YZ}$\ cm}
% \draw (Y) -- (Z) let
% \p1=($(Z) - (Y)$)
% in
% node[midway,right] {$\pgfmathveclen{\x1}{\y1}\pgfmathresult$};
%%%%%%%%%%%%%%%%%%%%%
\tkzMarkAngle(C,Y,Z)
\end{tikzpicture}
\end{document}
答案3
这是带有 TikZ 和 tkz-elements 的版本。创建 L.AB、L.CD 和 L.EF 对象后,可以自然获得线的交点。然后在 Lua 或 TikZ 中获取 YZ 段的长度。长度函数用于获取此长度。TikZ 宏 \tkzDN 用于格式化数字。\tkzUseLua
允许您使用 tkz-elements length(z.Y,z.Z
:。
with lualatex !!
\documentclass{article}
\usepackage{tikz,tkz-elements}
\begin{document}
\begin{tkzelements}
z.A = point : new (1,-3)
z.B = point : new (8,1)
z.C = point : new (1,0)
z.D = point : new (8,4)
z.E = point : new (6,-4)
z.F = point : new (6,4)
L.AB = line : new (z.A,z.B)
L.CD = line : new (z.C,z.D)
L.EF = line : new (z.E,z.F)
z.Z = intersection (L.AB,L.EF)
z.Y = intersection (L.CD,L.EF)
\end{tkzelements}
\begin{tikzpicture}
\tkzGetNodes
\draw[line width=1.5pt] (A) -- node[midway, below right]{a} (B);
\draw[line width=1.5pt] (C) -- node[midway, below right] {b} (D);
\draw[line width=1.5pt] (E) -- node[near end, right] {c} (F);
\path (Y) -- (Z) node[midway,right] {\tkzDN{\tkzUseLua{length(z.Y,z.Z)}}};
\end{tikzpicture}
\end{document}
如果不是 z.E = point : new (6,-4)' we use
zE = point: new (3,-4)`,我们得到:(不修改任何内容)