パスの交差を直接使用するForeachループ

パスの交差を直接使用するForeachループ

これが MWE です。2 つのパスを交差させて、ループを使用してすべての交差点をループします。交差点がいくつあるかは事前にわかりませんが、特にそれぞれに名前を付ける必要がないことを確実に期待しています。次のようなことができるようにしたいです。

%\foreach \p in {\path[name intersections={of = AE and MN}];}
%       \filldraw [red] (\p) circle(3pt);

最善のアプローチは何でしょうか?

\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}

\coordinate (ORG) at (0.00, 0.00);

% first path (zig zag blue)
\coordinate (A) at (1.00, 3.00);
\coordinate (B) at (3.00, -3.00);
\coordinate (C) at (5.00, 3.00);
\coordinate (D) at (7.00, -3.00);
\coordinate (E) at (9.00, 3.00);
\draw[blue, line width=1.50pt, name path = AE] (ORG) -- (A) -- (B) -- (C) -- (D) -- (E);

% second path (ForestGreen)
\coordinate (M) at (0.00, 2.00);
\coordinate (N) at (10.00, 2.00);
\coordinate (U) at (10.00, -2.00);
\coordinate (V) at (0.00, -2.00);
\draw[ForestGreen, line width=1.50pt, name path = MN] (M) -- (N) -- (U) -- (V);

% first path points
\filldraw [teal] (A) circle(3pt);
\filldraw [teal] (B) circle(3pt);
\filldraw [teal] (C) circle(3pt);
\filldraw [teal] (D) circle(3pt);
\filldraw [teal] (E) circle(3pt);

% intersections of the two paths
\path [name intersections={of = AE and MN}];
\coordinate (P)  at (intersection-1);
\coordinate (Q)  at (intersection-2);
\coordinate (R)  at (intersection-3);
\coordinate (S)  at (intersection-4);
\coordinate (T)  at (intersection-5);
\coordinate (W)  at (intersection-6);
\coordinate (X)  at (intersection-7);
\coordinate (Y)  at (intersection-8);
\coordinate (Z)  at (intersection-9);

% mark each intersection with a red dot
\foreach \p in {P,Q,R,S,T,W,X,Y,Z}
        \filldraw [red] (\p) circle(3pt);

%\foreach \p in {\path[name intersections={of = AE and MN}];}
%       \filldraw [red] (\p) circle(3pt);

\end{tikzpicture}

\end{document}

答え1

これはどう:

\draw[name path = AE] (ORG) -- (A) -- (B) -- (C) -- (D) -- (E);
\draw[name path = MN] (M) -- (N) -- (U) -- (V);

\fill [name intersections={of=AE and MN, name=i, total=\t}] [red] 
   \foreach \s in {1,...,\t} {
       (i-\s) circle (3pt) 
    };

関連情報