2

I've looked at this and that, and I'm unable to compile and use intersections of lines i give name inside the same foreach loop.

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}
    \begin{tikzpicture}
        \pgfmathsetmacro{\xsidelength}{2}
        \pgfmathsetmacro{\ysidelength}{1.5}
        \path[draw, dashed,name path global=star2] (0,0) --
            ++(\xsidelength,0) --
            ++(45:\ysidelength) --
            ++(-\xsidelength,0) --
            cycle;

        \pgfmathsetmacro{\halfylength}{\ysidelength/2}
        \coordinate (O) at ($(\xsidelength / 2,0)+(45:\halfylength)$);
        \node[draw, circle, inner sep=1pt] at (O) {};

        \foreach \angle[count=\i] in {22.5,0,...,-225}
        {
            \path[name path global/.expanded=line\i] (O) -- ++(\angle:\xsidelength);
            \draw[name intersections = {of {line\i} and star2}](intersection\i) circle (2pt);
        }
    \end{tikzpicture}
\end{document}

The first path is drawn, but its name is apparently not known inside the foreach, nor lines defined just a line above

And I've got next errors

:26: Package pgfkeys Error: I do not know the key '/tikz/intersection/of {line1} and star2' and I am going to ignore it. Perhaps you misspelled it.

:26: Package tikz Error: I do not know the path named `'. Perhaps you misspelt it.

:26: Package pgf Error: No shape named intersection1 is known.

Though, the example is not really minimal, I don't see what is different from answered questions, except i'm trying to reuse names inside the same foreach

1

Typos and a few small mistakes (marked with ! in code below):

  • \xvsidelength > \xsidelength (typo v)
  • (invtersection\i) > (intersection-1) (typo v & -1 because you are referring to the first intersection of every combination)
  • = {of {line\i} > = {of={line\i} (missing =)
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}
    \begin{tikzpicture}
    \pgfmathsetmacro{\xsidelength}{2}
    \pgfmathsetmacro{\ysidelength}{1.5}
    \path[draw, dashed,name path global=star2] (0,0) --
    ++(\xsidelength,0) --
    ++(45:\ysidelength) --
    ++(-\xsidelength,0) --
    cycle;

    \pgfmathsetmacro{\halfylength}{\ysidelength/2}
    \coordinate (O) at ($(\xsidelength / 2,0)+(45:\halfylength)$);
    \node[draw, circle, inner sep=1pt] at (O) {};

    \foreach \angle[count=\i] in {22.5,0,...,-225}
    {
        \path[name path global/.expanded=line\i] (O) -- ++(\angle:\xsidelength); % !
        \draw[name intersections = {of ={line\i} and star2}](intersection-1) circle (2pt); % !!!
    }
    \end{tikzpicture}
\end{document}

result

  • typos are not really present (fixed the copy in my question), but the "=" sign and -1 solved the problem. – dEmigOd Jun 24 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.