我想做一个循环,直到两条路径之间有交点
编辑
我画斜线直到它们不与圆相交。当没有交点时,我得到一个错误。有没有办法处理零交点?
\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}
答案1
我不明白到底发生了什么,但这应该有效;
\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}
抱歉,我现在无法编译,我会更新图片。