10

Why doesn't TikZ find all intersections. They are obviously there …

missing intersections

\documentclass[border=10mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[point/.style={fill=blue,minimum size=1mm,inner sep=0pt,circle}]
    % Zoom (to prevent oveflow)
    \def\yzoom{100}
    % Plots
    \foreach \T/\xmin/\a in {%
        0.27/1.538/a,
        0.28/1.590/b,
        0.29/1.649/c
    } {
        \draw [thin,name path global/.expanded={kurve \a}]
            plot [raw gnuplot] function {%
                set xrange [\xmin:10];
                set yrange [0:0.08*\yzoom];
                set samples 1000;
                f(x) = \yzoom*(\T/(x-1) - 1/(x**2));
                plot f(x);
            };
    }
    % Lines
    \foreach \p/\a in {%
        %% T = 0.27
        0.0231/a,
        %% T = 0.28
        0.02855/b,
        %% T = 0.29
        0.0338/c
    }{
        \draw [red,thin,name path global/.expanded={linie \a}]
            (0,\p*\yzoom) -- (10,\p*\yzoom) node [fill=white,pos=0.1] {\a};
    }
    % Intersections points
    \path [name intersections={of=kurve a and linie a,by={P1,P2,P3}}]
        (P1) node [point] {} (P2) node [point] {} (P3) node [point] {};
    \path [name intersections={of=kurve b and linie b,by={P1,P2,P3}}]
        (P1) node [point] {} (P2) node [point] {} (P3) node [point] {};
    \path [name intersections={of=kurve c and linie c,by={P1,P2,P3}}]
        (P1) node [point] {} (P2) node [point] {} (P3) node [point] {};
\end{tikzpicture}
\end{document}

There seems to be no problem with the names of the paths but TikZ is missing four intersection points.

Bonus question: Is it possible to solve the last part (adding blue points) with the second \foreach? I tried it but I get the error File ended while scanning use of \tikz@intersect@path@names@parse..

2
  • 1
    The first paragraph of the PGF 2.10 manual (section 13.3.2 "Intersections of Arbitrary Paths") states "due to the low accuracy of TEX ... you should not try to intersect paths consisting lots of very small segments such as plots or decorated paths". You could try changing the value of the macro \pgfintersectiontolerance (currently \defed to 0.1pt) to a smaller (positive) value, as it is (more or less) the smallest subpath length that is considered, but a too small value may increase the running time significantly and still not produce satisfactory results. Aug 9, 2013 at 10:15
  • @MarkWibrow: Thanks. That works for the a and b path but not the c path even 0.000001pt doesn’t help …
    – Tobi
    Aug 9, 2013 at 11:29

1 Answer 1

10

I don’t know why PGF doesn’t find these intersections, it probably has do to something with how the path is built internally from the points of the table of values gnuplot creates.

It works if you either

  • set set samples 100 or
  • use—with the original samples setting—the smooth option.

All intersections are found now.


The of key (\tikz@intersect@path@names@parse) expects spaces around and which is obviously stripped if you use of=kurve \a and linie \a, so you will need to do of/.expanded=kurve \a\space and linie \a or of={kurve \a} and linie \a.

You also might introduce spurious spaces with \foreach in:

\foreach \p/\a in {%
    %% T = 0.27
    0.0231/a,
    %% T = 0.28
    0.02855/b,
    %% T = 0.29
    0.0338/c             % <- there’s a space!
}{

This space actually may help if you .expanded with the of key but is usually trouble so avoiding this is reccomended.

(That space is also present in the other \foreach loop but as it is used with an .expanded before PGFkeys processes it, it is stripped.)

Code

\documentclass[convert=false,tikz]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[point/.style={fill=blue,minimum size=1mm,inner sep=0pt,circle}]
    % Zoom (to prevent oveflow)
    \def\yzoom{100}
    % Plots
    \foreach \T/\xmin/\a in {
        0.27/1.538/a,
        0.28/1.590/b,
        0.29/1.649/c
    } {
        \draw [thin,smooth,name path global/.expanded={kurve \a}]
            plot [raw gnuplot] function {%
                set xrange [\xmin:10];
                set yrange [0:0.08*\yzoom];
                set samples 1000;
                f(x) = \yzoom*(\T/(x-1) - 1/(x**2));
                plot f(x);
            };
    }
    % Lines
    \foreach \p/\a in {%
        %% T = 0.27
        0.0231/a,
        %% T = 0.28
        0.02855/b,
        %% T = 0.29
        0.0338/c%
    }{
        \draw [red,thin,name path global/.expanded={linie \a}]
            (0,\p*\yzoom) -- (10,\p*\yzoom) node [fill=white,pos=0.1] {\a};
        \path [name intersections={of={kurve \a} and linie \a, total=\t}] \foreach \s in {1,...,\t} {(intersection-\s) node[point]{}};
    }
\end{tikzpicture}
\end{document}

Output

enter image description here

2
  • Works fine, thank you! But in my real document the smooth option leads to small hooks at the end of each graph: imgur.com/vR0su5R. Do you have an idea how to prevent this?
    – Tobi
    Aug 9, 2013 at 9:15
  • Ahh … the problem where the line caps that I drawed as arrow heads. I changed to line cap=round and that works fine.
    – Tobi
    Aug 9, 2013 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .