4

I'm specifically interested in the case in which lines AB and CD intersect, but outside (of at least one) of the segments AB, CD, and get the intersection I for further work. The similar questions only handle the case in which the segments intersect.

vonbrand
  • 5,473

2 Answers2

6

There is another way to find the intersection of two intersecting lines that is no longer documented in manual 3.0.1a but still works. It is on page 87 of manual 1.18 which you will find here (until when?): tikz pgf manual 1.18

It consists in solving a system of 2 equations with 2 unknowns (the points that define the 2 lines). It is not necessary for the paths to intersect on the figure to find their intersection unlike the version given in manual 3.01a of the solution given by ignasi. The second advantage is that it is not necessary to load any library for this to work.

You will notice that the points or their coordinates are named without parentheses:

intersection of A--B and 0,3--2,2

Line A--B shorter as suggested by @marmot

intersection

\documentclass[tikz,border=2mm]{standalone} 
\begin{document}
\begin{tikzpicture}
\draw[help lines] (0,0) grid (3,3);
\draw (0,0) coordinate (A)node[below]{A} -- (2,1.5) coordinate (B)node[below right]{B}
(0,3)node[below left]{C} -- (2,2)node[below left]{D};
\fill[blue] (intersection of A--B and 0,3--2,2) circle (2pt);
\end{tikzpicture}
\end{document}

Translated with www.DeepL.com/Translator

AndréC
  • 24,137
  • @marmot, I don't know more than the given points A, B, C, D. Just drawing part of the line is no help. – vonbrand Sep 13 '18 at 14:42
  • @vonbrand Finally, I don't know if I understood your question correctly. Have you read the update of my answer? – AndréC Sep 13 '18 at 14:50
  • I believe this is deprecated in current TikZ... there is no section 1.18 in current version 3.0.1a of the TikZ & PGF manual. Page 118 gives an example of segments that do intersect. – vonbrand Sep 13 '18 at 14:50
  • @vonbrand No, it works. it had been deleted, then at the request of the users, it was delivered (but without the doc). it's not the only thing like that with tikz, there is also shorten > which still works but is only documented in the manual 1.18. – AndréC Sep 13 '18 at 14:52
  • 1
    @vonbrand It is still official, though with a slightly different syntax. See page 118 (instead of section 1.18) of the pgfmanual. Try \draw (0,0) coordinate(A) -- (1,2) coordinate(B); \draw (3.5,0) coordinate(C)-- (3,2) coordinate(D); \coordinate (X) at (intersection cs:first line={(A)--(B)}, second line={(C)--(D)}); \fill[red] (X) circle (1pt);. –  Sep 13 '18 at 16:16
5
  1. Declare two path which intersect.
  2. Computes and draw the intersection point.
  3. Draw (or not) some fragment of original paths.

That's all.

\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{intersections, calc}

\begin{document}
\begin{tikzpicture}
\path[name path=a] (0,0) coordinate (a1) -- (2,4) coordinate (a2);
\path[name path=b] (0,4) coordinate (b1) -- (5,2) coordinate (b2);
\fill[red,name intersections={of=a and b}]
    (intersection-1) circle (2pt);

\draw (a1)--($(a1)!.5!(a2)$);
\draw (b2)--($(b2)!.5!(b1)$);
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588