1

Here is my 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}

Simply, I am trying to mark the intersection points between a circle and a line, and draw a thick line between those points.

The above code works properly. But when I change the names of the intersection from (intersection-1) and (intersection-2) to something like i1 and i2, I get the error:

! Package pgf Error: No shape named i1 is known.
! Package pgf Error: No shape named i2 is known.

Must the names of the intersections begin with the word intersection?

1 Answer 1

2

https://tex.stackexchange.com/a/478227/197451

The relevant line is

\path [name intersections={of=D and E, by={C, C’}}];

Here the intersection points are computed and named C and C' ("name the intersection points of D and E by the names C and C'").

It is shortcut for

\coordinate (C) at ...;
\coordinate (C') at ...;

for some computed coordinates.

enter image description here

\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}

edit

enter image description here

\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}
2
  • Thanks! Just out of curiosity, is there a way to name the intersections without \fill or \draw commands?
    – padawan
    Commented Aug 16, 2020 at 17:03
  • 1
    of course -- please see edit
    – js bibra
    Commented Aug 16, 2020 at 17:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.