2

I would like to draw a pentagon. This works

\draw \foreach \alpha in {0,72,...,359} {
    \ifdim\alpha pt=0pt \else--\fi
    (270+\alpha:1) 
} -- cycle;

while this

\draw \foreach \alpha in {0,72,...,359} {
    (270+\alpha:1) --
} cycle;

gives the error Cannot parse this coordinate.

Can someone explain why?

gTcV
  • 1,065
  • 3
    See this one http://tex.stackexchange.com/a/132162/3235 – percusse Jan 14 '15 at 21:30
  • Very stupid interface from the part of LaTeX/TikZ! But thanks a lot for the explanation, this will save my computer a few occasions of being shouted at. – gTcV Jan 15 '15 at 07:44
  • Why stupid? For example the proper way is \draw (270:1) \foreach\x in{1,...,4}{--(270+\x*72:1)}--cycle;. – percusse Jan 15 '15 at 13:44
  • Because I have to give special treatment to the first step. Not much of an issue in this simple example, but very nasty once it gets more complicated. – gTcV Jan 15 '15 at 14:38
  • Open another question or edit this one to include the nasty case. Then you can ask for others' opinion for simplifications. People tend to love TikZ code golfing. – percusse Jan 15 '15 at 14:40
  • Do you know regular polygon shape? http://tex.stackexchange.com/a/212584/1952 or http://tex.stackexchange.com/a/179847/1952 – Ignasi Jan 19 '15 at 15:53

1 Answers1

1

You can define the path before to use it:

\documentclass[varwidth,border=7mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
  \xdef\p{}
  \foreach \alpha in {0,72,...,359}{
    \xdef\p{\p (270+\alpha:1) --}
  }
  \begin{tikzpicture}
    \draw \p cycle;
  \end{tikzpicture}
\end{document}

enter image description here

Kpym
  • 23,002