我正在尝试绘制一个循环,其中线 AB 和 CD 与 1-2 和 3-4 线重叠。
- 当上面和下面的编号线与其他编号线交叉时,可以修剪或剪裁吗?
- 有没有其他方法可以计算交叉点,以便我可以简单地将它们放入坐标中?
我已经花了几个小时看完这部纪录片,但却找不到办法。
\begin{tikzpicture} [>=latex]
\draw [->, thick] (0,0) -- (10,0);
\draw [->, thick] (0,0) -- (0,8);
\coordinate (A) at (0.5,1.5);
\coordinate (B) at (8.5,7.5);
\coordinate (C) at (8.5,4);
\coordinate (D) at (0.5,0.5);
\coordinate [label=below:$1$] (1) at (1.5,0.5);
\coordinate [label=above:$2$] (2) at (1.5,2.5);
\coordinate [label=above:$3$] (3) at (7.5,7);
\coordinate [label=below:$4$] (4) at (7.5,3);
\draw [-] (A) to[out=25,in=230] (B);
\draw [-] (C) to[out=215,in=15] (D);
\draw [-] (1) to (2);
\draw [-] (3) to (4);
\end{tikzpicture}
答案1
您可以使用剪辑,但这里有一个使用交叉点库的答案:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[>=latex]
\draw [->, thick] (0,0) -- (10,0);
\draw [->, thick] (0,0) -- (0,8);
\coordinate (A) at (0.5,1.5);
\coordinate (B) at (8.5,7.5);
\coordinate (C) at (8.5,4);
\coordinate (D) at (0.5,0.5);
\coordinate [label=below:$1$] (1) at (1.5,0.5);
\coordinate [label=above:$2$] (2) at (1.5,2.5);
\coordinate [label=above:$3$] (3) at (7.5,7);
\coordinate [label=below:$4$] (4) at (7.5,3);
\draw [-, name path=A to B] (A) to[out=25,in=230] (B);
\draw [-, name path=C to D] (C) to[out=215,in=15] (D);
\path [-, name path=1 to 2] (1) to (2);
\path [-, name path=3 to 4] (3) to (4);
\tikzset{
name intersections={of=A to B and 1 to 2, by={X1}},
name intersections={of=C to D and 1 to 2, by={Y1}},
name intersections={of=A to B and 3 to 4, by={X2}},
name intersections={of=C to D and 3 to 4, by={Y2}}
}
\draw (X1) -- (Y1);
\draw (X2) -- (Y2);
\useasboundingbox (-0.5,-0.5) rectangle (10.5, 8.5);
\end{tikzpicture}
\end{document}
编辑:将交叉点的规范更改为单个命令\tikzset
而不是多个\path
命令。