# Lines generated with TikZ intersections are too short

My script calculates several intersections of lines (green) with a vertical "wall" (not shown). The intersections (small red dots) are fine. But the lines from one intersection to another intersection are too short (blue). I don't have any idea what's wrong with the script:

\documentclass[a4paper]{scrartcl}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}

\begin{document}
\begin{tikzpicture}
\def\wallx{6cm}
\def\scannerx{0cm}
\def\scannery{0.0cm}
\def\walllength{8cm}

\coordinate (WALLBEGIN) at ($(\wallx, 0.5*\walllength)$);
\coordinate (WALLEND) at ($(\wallx, -0.5*\walllength)$);
\coordinate (SCANNER) at (\scannerx, \scannery);
\path[name path=wall] (WALLBEGIN) -- (WALLEND);

%calculate intersections
\foreach \index in {0,...,4} {
%calculates the ray from scanner to wall
\def\raylength{12cm}
\coordinate (REL) at ({9*(\index-2)+1}:\raylength);
\coordinate (RAYEND) at ($(SCANNER)+(REL)$);
\path [name path=ray] (SCANNER) -- (RAYEND);

%intersection with wall
\path [name intersections={of=ray and wall,by=X}];
\node (iwall\index) at (X) {};

%THIS INTERSECTION IS OK
\filldraw[fill=red] (X) circle (0.05cm);
\draw[green] (SCANNER) -- (RAYEND);
}

% LINE BETWEEN TWO INTERSECTIONS WHICH IS TOO SHORT
\draw[blue] (iwall0) -- (iwall1);

\end{tikzpicture}
\end{document}

-
Just using \coordinate (iwall\index) instead of \node fixes the problem. coordinate nodes don't take up any space, while empty nodes still have the white space caused by the inner sep. –  Jake Apr 28 '12 at 19:30
Or if you want to add some material to the node you can use: \draw[blue] (iwall0.center) -- (iwall1.center); –  Marco Daniel Apr 28 '12 at 19:31
Thank you for your help! –  Sebastian Apr 28 '12 at 19:42

Instead of adding nodes to save the intersection coordinates, you can just use \path [name intersections={of=ray and wall,by=X\index}];. The intersections will then be available as X0, X1, and so forth.

You could then "overwrite" these coordinates with circular nodes with an inner sep=0pt: the inner sep of your empty nodes caused the problem with the "detached" lines. They weren't actually deteched, they connected with the invisible border of your empty nodes.

In general, empty nodes aren't the best thing to use if you just want to save a point, since even empty nodes take up space (caused by the inner sep, which you could set to zero as a workaround). \coordinate (or, equivalently, \node [coordinate] are better for this task.

\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}

\begin{document}
\begin{tikzpicture}
\def\wallx{6cm}
\def\scannerx{0cm}
\def\scannery{0.0cm}
\def\walllength{8cm}

\coordinate (WALLBEGIN) at ($(\wallx, 0.5*\walllength)$);
\coordinate (WALLEND) at ($(\wallx, -0.5*\walllength)$);
\coordinate (SCANNER) at (\scannerx, \scannery);
\path[name path=wall] (WALLBEGIN) -- (WALLEND);

%calculate intersections
\foreach \index in {0,...,4} {
%calculates the ray from scanner to wall
\def\raylength{12cm}
\coordinate (REL) at ({9*(\index-2)+1}:\raylength);
\coordinate (RAYEND) at ($(SCANNER)+(REL)$);
\path [name path=ray] (SCANNER) -- (RAYEND);

%intersection with wall
\path [name intersections={of=ray and wall,by=X\index}];

% use a circular node for drawing the circles
\node [draw,fill=red,circle, inner sep=0pt, minimum size=4pt] (X\index) at (X\index) {};
\draw[green] (SCANNER) -- (RAYEND);
}

\draw[blue] (X1) -- (X2);