这是我的 MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=3]
\draw[name path={circle}] (0,0) circle(1cm);
\draw[name path={h1}] (-2,0) -- (2,0);
\draw[name path={h2}] (-2,0.8) -- (2,0.8);
\fill[name intersections={of=circle and h2}]
(intersection-1) circle(0.5pt)
(intersection-2) circle(0.5pt);
\fill[red] (0,0) circle(1pt);
\draw[ultra thick] (intersection-1)--(intersection-2);
\end{tikzpicture}
\end{figure}
\end{document}
简单来说,我想标记一个圆和一条线之间的交点,并在这些点之间画一条粗线。
上述代码运行正常。但是当我将交叉点的名称从(intersection-1)
和更改为和 之(intersection-2)
类的名称时,我收到错误:i1
i2
! Package pgf Error: No shape named i1 is known.
! Package pgf Error: No shape named i2 is known.
交叉路口的名称必须以单词 开头吗intersection
?
答案1
https://tex.stackexchange.com/a/478227/197451
相关行是
\path [name intersections={of=D and E, by={C, C’}}];
这里计算交点并命名为C
和C'
(“将 D 和 E 的交点命名为 C 和 C'”)。
这是快捷方式
\coordinate (C) at ...;
\coordinate (C') at ...;
对于一些计算出的坐标。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=3]
\draw[name path={circle}] (0,0) circle(1cm);
\draw[name path={h1}] (-2,0) -- (2,0);
\draw[name path={h2}] (-2,0.8) -- (2,0.8);
\fill[red, name intersections={of=circle and h2, by={C, C'}}]
(C) circle(1pt)
(C') circle(1pt);
\fill[red] (0,0) circle(1pt);
\draw[ultra thick, red] (C)--(C');
\end{tikzpicture}
\end{figure}
\end{document}
编辑
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=3]
\draw[name path={circle}] (0,0) circle(1cm);
\draw[name path={h1}] (-2,0) -- (2,0);
\draw[name path={h2}] (-2,0.8) -- (2,0.8);
\path[name intersections={of=circle and h2, by={C, C'}}];
\fill[red] (0,0) circle(1pt);
\draw[ultra thick, red] (C)--(C');
\end{tikzpicture}
\end{figure}
\end{document}