
2 つのパスの交差点を特定の順序で取得したいと思います。
これらのパスを 2D 画像として描画すると、すべて正常になります。
しかし、何らかの理由で、ライブラリを使用して同じ図をプロットすると、キー3d
に関係なく、交差の順序が変わりますsort by
。
3D の場合に正しい順序を取得する方法を誰か知っていますか?
MWE:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d, intersections}
\begin{document}
% 2D picture : order of intersections is OK
\begin{tikzpicture}
\draw[red, name path = structure] (3,-1)coordinate(A) -- (3,1) -- (1,1)coordinate(B) -- (0,0) -- (2,0) -- (3,1);
\draw[blue,->, name path = line] (A) -- (B);
\draw [name intersections={of=structure and line, name=i, sort by=line}] (i-1) node{+}node[below]{1} (i-2) node{+}node[below]{2} (i-3) node{+}node[below]{3};
\end{tikzpicture}
% 3D picture : order of intersections is weird
\begin{tikzpicture}[x = {(1cm,0cm)}, y = {(0.5cm,0.5cm)}, z = {(0cm,1cm)}]
\draw[red, name path = structure] (2,2,0)coordinate(A) -- ++(0,0,2) --++(-2,0,0)coordinate(B) --++(0,-2,0) --++(2,0,0) --++(0,2,0);
\draw[blue,->, name path = line] (A) -- (B);
\draw [name intersections={of=structure and line, name=i, sort by=line}] (i-1) node{+}node[below]{1} (i-2) node{+}node[below]{2} (i-3) node{+}node[below]{3};
\end{tikzpicture}
\end{document}
2D画像:
3D画像:
答え1
私の意見では、これは3Dとは何の関係もありませんが、構文で描かれた直線に沿ってソートすると、--
結果が少し運次第になるという事実に関係しています。これについては、以下で長々と議論されています。この質問これを解くには、曲線のように見える直線を描くことができます。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d, intersections}
\begin{document}
% 2D picture : order of intersections is OK
\begin{tikzpicture}
\draw[red, name path = structure] (3,-1)coordinate(A) -- (3,1) -- (1,1)coordinate(B) -- (0,0) -- (2,0) -- (3,1);
\draw[blue,->, name path = line] (A) -- (B);
\draw [name intersections={of=structure and line, name=i, sort by=line}] (i-1) node{+}node[below]{1} (i-2) node{+}node[below]{2} (i-3) node{+}node[below]{3};
\end{tikzpicture}
% 3D picture : order of intersections is weird
\begin{tikzpicture}[x = {(1cm,0cm)}, y = {(0.5cm,0.5cm)}, z = {(0cm,1cm)}]
\draw[red, name path = structure] (2,2,0)coordinate(A) -- ++(0,0,2) --++(-2,0,0)coordinate(B) --++(0,-2,0) --++(2,0,0) --++(0,2,0);
\draw[blue,->, name path = line] (A) to[bend left=0] (B);
\draw [name intersections={of=structure and line, name=i, sort by=line}] (i-1) node{+}node[below]{1} (i-2) node{+}node[below]{2} (i-3) node{+}node[below]{3};
\end{tikzpicture}
\end{document}