[Tex/LaTex] Tikz intersection of lines with unnamed points

intersectionspgfmathtikz-pgf

This works:

\draw (0,0) coordinate (A);
\draw (1,1) coordinate (B);
\draw (1,0) coordinate (C);
\draw (0,1) coordinate (D);
\coordinate (X) at (intersection of A--B and C--D);

but this doesn't:

\draw (0,0) coordinate (A);
\draw (1,1) coordinate (B);
\coordinate (X) at (intersection of A--B and (0,1)--(1,0));

I think it would be a great convenience to use points as in the second example, where they don't have to be named before being used as endpoints of lines.

Is there any way of coercing TiKZ to create intersections of lines given by endpoints, without naming those endpoints first?

Best Answer

With intersections library you don't need to name each coordinate but each path

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\begin{tikzpicture}
\draw (0,0) coordinate (A);
\draw (1,1) coordinate (B);
\draw (1,0) coordinate (C);
\draw (0,1) coordinate (D);
\draw (A)--(B);\draw (C)--(D);  % added for `cross symbol` demonstration
\coordinate (X) at (intersection of A--B and C--D);

%

\begin{scope}[xshift=2cm]    % so that they won't overlap
\draw[name path=AB] (0,0)  -- (1,1);
\draw[name path=CD] (0,1) -- (1,0);
\draw [name intersections={of=AB and CD, by=x}] (x) circle (2pt)node[right] {$x$};
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here