4

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?

  • 1
    An MWE would be nice. Not everyone will know how to turn this into something you can compile (or not). – cfr Nov 9 '14 at 3:49
4

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

1

This is an attempt where the (...) in (1,0)--(0,1) is replaced by {...}.

enter image description here

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\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 (0,0)  coordinate (A);
\draw (1,1)  coordinate (B);
%\draw (1,0) coordinate (C);
%\draw (0,1) coordinate (D);
\node (Y) at (intersection of A--B and {0,1}--{1,0}){Y}; % change coordinate to node for showing Y
\end{scope}
\end{tikzpicture}

\end{document}

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.