# Do until there is no intersection point

I want to do a loop until there is intersection points between two paths

edit

I oblic lines until they don't intersect the circle. When there is zero intersection points I have an error. Is there a way to deal with zero intersection points ?

\documentclass[tikz,margin=3pt]{standalone}
%\usepackage{}
\usetikzlibrary{calc,intersections}

\def\Dir{45}
\def\DirStep{1pt}
\def\Length{10}

\begin{document}

\begin{tikzpicture}

\coordinate (Depart) at (0,0) ;

\begin{scope}[shift=(Depart),rotate=\Dir]
\clip[name path=bob,draw] (0,0) circle (1) ;

\pgfmathtruncatemacro\i{0}

\loop
\draw[name path=trait,shift={(0,\i*\DirStep)}] (-5,0)--(5,0) ;
\path[name intersections={%
of=trait and bob,
name=\i,
sort by=trait,
total=\t}]
\pgfextra{\xdef\InterNb{\t}} ;
\pgfmathtruncatemacro\i{\i+1}
\ifnum\i<10
% I want :
%\ifnum\\InterNb>0
\repeat

\end{scope}

\node   {\InterNb} ;
\end{tikzpicture}

\end{document}

• Jun 10 '14 at 9:36
• It's not the problem, see my edit. The question was onscur. Sorry. Jun 10 '14 at 10:26

I didn't understand what exactly happening but this should work;

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

\def\Dir{45}
\def\DirStep{1}
\def\Length{10}

\begin{document}
\begin{tikzpicture}

\coordinate (Depart) at (0,0) ;

\begin{scope}[shift=(Depart),rotate=\Dir]
\clip[name path=bob,draw] (0,0) circle (1) ;

\foreach\i[count=\xi from 0] in {0,\DirStep,...,10}{
\draw[name path=trait,shift={(0,\i pt)}] (-5,0)--(5,0) ;
\path[name intersections={%
of=trait and bob,
name=\i,
sort by=trait,
total=\t}]
\pgfextra{\xdef\InterNb{\t}};
\ifnum\InterNb>0\relax
\breakforeach
\fi
}
\end{scope}
\node   {\InterNb} ;
\end{tikzpicture}

\end{document}


Sorry, I can't compile it right now I'll update the picture.

• It compiles but it doesn't do what I want. See my edit. Jun 10 '14 at 10:25
• @Tarass It's probably the sort by key messing it up when there is no intersection. Can you try without? Jun 10 '14 at 11:03
• It works without. I suppose I have to do without ... Thank you. Jun 10 '14 at 13:56