经过一个点并且与另一个点平行的线:我错在哪里了?

经过一个点并且与另一个点平行的线:我错在哪里了?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}

    \coordinate (A) at (0,0);
    \coordinate (B) at (2,4);
    \coordinate (C) at (8,0);
    \coordinate (M) at (4,0);

    \path[name path=Circle] (B) circle [radius=3cm];
    \path[name path=AB] (A)--(B);
    \path[name path=BC] (B)--(C);
    \path [name intersections={of=Circle and BC}];
    \coordinate (E) at (intersection-1);
    \path [name intersections={of=Circle and AB}];
    \coordinate (D) at (intersection-1);

    \draw[thick](A)--(B)--(C)--cycle;
    \draw[thick](B) circle [radius=3cm];
    \draw[thick](D)--(E)  (M)--(B);

    % From a point draw a parallel line by calculating the vector
    \coordinate (P) at (intersection cs:first line={(B)--(C)}, second line={(A) -- +($(E)-(D)$)});

    % Here is my problem:
    \coordinate (N) at (intersection cs:first line={(B)--(M)}, second line={(C) -- +($(D)-(E)$)});

    \draw[thick, red] (A)--(P) (C)--(N);

\end{tikzpicture}
\end{document}

问题:第二条线也应该平行,但实际上不是。我做错了什么?

在此处输入图片描述

答案1

如果您+在这种上下文中使用语法,它似乎并不总是能给您预期的结果。一般来说,+表示“相对于此路径的第一个坐标”。但是谁知道上下文中的第一个坐标是什么intersection cs:?然而,仅通过计算斜率并使用它就可以生成平行线,这并不太难。为了清楚起见,我标记了所有坐标。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}

    \coordinate[label=left:$A$] (A) at (0,0);
    \coordinate[label=above:$B$] (B) at (2,4);
    \coordinate[label=right:$C$] (C) at (8,0);
    \coordinate[label=45:$M$] (M) at (4,0);

    \draw[name path=Circle] (B) circle [radius=3cm];
    \path[name path=AB] (A)--(B);
    \path[name path=BC] (B)--(C);
    \path [name intersections={of=Circle and BC}];
    \coordinate[label=right:$E$] (E) at (intersection-1);
    \path [name intersections={of=Circle and AB}];
    \coordinate[label=left:$D$] (D) at (intersection-1);

    \draw[thick](A)--(B)--(C)--cycle;
    %\draw[thick](B) circle [radius=3cm];
    \draw[thick](D)--(E)  (M)--(B);

    % From a point draw a parallel line by calculating the vector
    \path  let \p1=($(E)-(D)$),\n1={atan2(\y1,\x1)} in 
    ($(A)+(\n1:1)$) coordinate (auxA) 
    ($(C)+(\n1:1)$) coordinate (auxC);
    \coordinate[label=right:$P$] (P) at (intersection cs:first line={(B)--(C)},
    second line={(A) -- (auxA)});

    % Here is my problem:
    \coordinate[label=below:$N$] 
    (N) at (intersection cs:first line={(B)--(M)},
    second line={(C) -- (auxC)});

    \draw[thick, red] (A)--(P) (C)--(N) ;

\end{tikzpicture}
\end{document}

在此处输入图片描述

如您所见,红线是平行的。

One may want cast this into a style:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\begin{document}
\tikzset{line through/.style args={#1 parallel to line through #2 and #3 and
length #4}{insert path={%
let \p1=($(#3)-(#2)$),\n1={atan2(\y1,\x1)} in (#1) -- ++ (\n1:#4)}}}
\begin{tikzpicture}

    \coordinate[label=left:$A$] (A) at (0,0);
    \coordinate[label=above:$B$] (B) at (2,4);
    \coordinate[label=right:$C$] (C) at (8,0);
    \coordinate[label=45:$M$] (M) at (4,0);

    \draw[name path=Circle] (B) circle [radius=3cm];
    \path[name path=AB] (A)--(B);
    \path[name path=BC] (B)--(C);
    \path [name intersections={of=Circle and BC}];
    \coordinate[label=right:$E$] (E) at (intersection-1);
    \path [name intersections={of=Circle and AB}];
    \coordinate[label=left:$D$] (D) at (intersection-1);

    \draw[thick](A)--(B)--(C)--cycle;
    %\draw[thick](B) circle [radius=3cm];
    \draw[thick](D)--(E)  (M)--(B);

    % From a point draw a parallel line by calculating the vector
    \path[line through=A parallel to line through E and D and length 1]
    coordinate (auxA)
    [line through=C parallel to line through E and D and length 1] 
    coordinate (auxC);

    \coordinate[label=right:$P$] (P) at (intersection cs:first line={(B)--(C)},
    second line={(A) -- (auxA)});

    % Here is my problem:
    \coordinate[label=below:$N$] 
    (N) at (intersection cs:first line={(B)--(M)},
    second line={(C) -- (auxC)});

    \draw[thick, red] (A)--(P) (C)--(N) ;

\end{tikzpicture}
\end{document}

答案2

使用second line={(C)--($(C)+(D)-(E)$)})。第一个按预期工作,因为(A)=(0,0)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}

    \coordinate[label=A] (A) at (0,0);
    \coordinate[label=B](B) at (2,4);
    \coordinate[label=C] (C) at (8,0);
    \coordinate[label=M] (M) at (4,0);

    \path[name path=Circle] (B) circle [radius=3cm];
    \path[name path=AB] (A)--(B);
    \path[name path=BC] (B)--(C);
    \path [name intersections={of=Circle and BC}];
    \coordinate[label=E] (E) at (intersection-1);
    \path [name intersections={of=Circle and AB}];
    \coordinate[label=D] (D) at (intersection-1);

    \draw[thick](A)--(B)--(C)--cycle;
    \draw[thick](B) circle [radius=3cm];
    \draw[thick](D)--(E)  (M)--(B);

    % From a point draw a parallel line by calculating the vector
    \coordinate[label=P] (P) at (intersection cs:first line={(B)--(C)}, second line={(A) -- +($(E)-(D)$)});

    % Here is my problem:
    \coordinate[label=N] (N) at (intersection cs:first line={(B)--(M)}, second line={(C)--($(C)+(D)-(E)$)}); % <------


    \draw[thick, red] (A)--(P) (C)--(N);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容