Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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\scannerradius{0.4cm}
        \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);

        \filldraw[fill=gray!50!white] (SCANNER) circle (\scannerradius);
    \end{tikzpicture}
\end{document}
share|improve this question
3  
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

1 Answer 1

up vote 4 down vote accepted

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\scannerradius{0.4cm}
        \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);

        \filldraw[fill=gray!50!white] (SCANNER) circle (\scannerradius);
    \end{tikzpicture}
\end{document}
share|improve this answer
    
Ahh, thank you for your anwswer. It fixed my problem and now I understand what's the difference between nodes and coordinates. –  Sebastian Apr 28 '12 at 19:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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