我有一条被圆包围的短线,想找到这条线与圆延伸的交点。
下面的代码是我的 MWE。我认为错误是由于没有找到交点而导致的,因为作为线段,该线不与圆相交。那么如何才能最好地解决这个问题呢?
以下是我目前所掌握的信息:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (X) at (0,0);
\coordinate (A) at (1,1);
\coordinate (B) at (2,2);
\coordinate (C) at (3,0);
\draw (A) -- (B);
\draw[name path=AB] (A)--(B);
\node[draw,name path=K1] at (X) [circle through=(C)]{};
\path [name intersections={of=K1 and AB}];
\coordinate [label=above:$D$] (D) at (intersection-1);
\coordinate [label=above:$E$] (E) at (intersection-2);
\end{tikzpicture}
\end{document}
答案1
您可以不绘制线而直接延长线。最简单的方法是使用calc
库。该overlay
选项表示路径不会添加到图片大小中。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through}
\usetikzlibrary{intersections,calc}
\begin{document}
\begin{tikzpicture}
\coordinate (X) at (0,0);
\coordinate (A) at (1,1);
\coordinate (B) at (2,2);
\coordinate (C) at (3,0);
\draw (A) -- (B);
\path[overlay,name path=AB] ($(B)!10cm!(A)$)--($(A)!10cm!(B)$);
\node[draw,name path=K1] at (X) [circle through=(C)]{};
\path [name intersections={of=K1 and AB}]
(intersection-1) coordinate [label=above:$D$] (D)
(intersection-2) coordinate [label=above:$E$] (E);
\end{tikzpicture}
\end{document}
答案2
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{through}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\coordinate [label=x](X) at (0,0);
\coordinate [label=a](A) at (-4,-4);
\coordinate [label=b](B) at (3,3);
\coordinate [label=c](C) at (3,0);
\draw (A) -- (B);
\draw[name path=AB] (A)--(B);
\node[draw,name path=K1] at (X) [circle through=(C)]{};
\path [name intersections={of=K1 and AB}];
\coordinate [label=above:$D$] (D) at (intersection-1);
\coordinate [label=above:$E$] (E) at (intersection-2);
\end{tikzpicture}
\end{document}