4
\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}

Question: The second drawn line, which is supposed to also be a parallel, is not. What am I doing wrong?

enter image description here

4

If you use the + syntax in this context, it seems not to always give you what one may expect. In general, + means "relative to the first coordinate of this path". But who knows what the first coordinate is in the context of intersection cs:? It is, however, not too difficult to produce the parallel lines just by computing the slope and using it. For the sake of clarity, I labeled all coordinates.

\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}

enter image description here

As you see, the red lines are parallel.

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}
  • @blackened Yes, there it is very clear what the first point of the path is. Therefore, it is clear what + does. However, in the context of intersection cs: it is not clear to me where single paths start and end, and hence -- +(coordinate) may not be what one may thing it is. I am sorry if you feel that my wording is offensive, would like to apologize, and change it right away. – marmot Dec 25 '18 at 6:37
  • @blackened What precisely do you want the style to accomplish? A line through a given point with the slope coinciding with the one of another line. (And rereading my original post I think my wording did indeed not reflect what I wanted to say.) – marmot Dec 25 '18 at 6:42
  • @blackened I added this very style. What styles can one add? I guess pretty much everything. If you can achieve something of this kind, you can always make use of insert path in order to cast it into a style. (Hafid Boukhoulda's nice answer achieves the same and solves the problem by not using relative coordinates. This answer is simpler, mine has the slight advantage that you can control the length of the parallel lines.) – marmot Dec 25 '18 at 6:51
  • I combined this other answer by you, with this one: \path[line through=C parallel to line through A and B and length 1] coordinate (aux1); \path[towards={aux1 from C with length from A to B}] coordinate(E);. I had to do it like that, it is not possible to do it in one line, right? – blackened Mar 21 at 8:58
  • @blackened Sorry, I have really gone back and forth between these answers for some 30 minutes and honestly do not understand what you want to do. This is because you mix two answers and both of them have coordinates with the same name. And there is a simple remedy: ask a new question with an MWE from which one can understand what you are asking. – marmot Mar 21 at 14:53
4

Use second line={(C)--($(C)+(D)-(E)$)}). The first one works as expected because (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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.