使用 3d tikz 库的交叉点顺序问题

使用 3d tikz 库的交叉点顺序问题

我想按特定顺序获取两条路径之间的交点。

当这些路径被绘制成2D图片时,一切都很好。

但是由于某种原因,当我使用该库绘制相同的图形时,3d尽管有键,但交叉点的顺序会发生变化sort by

有人知道如何在 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) -- (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图片:

2D图片

3D图片:

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}

在此处输入图片描述

相关内容