I'm desperately trying to make this work
\documentclass{minimal}
\usepackage{tikz}
\newcommand\polygon[3][]{
\pgfmathsetmacro{\angle}{360/#2}
\pgfmathsetmacro{\startangle}{0}
\begin{scope}[#1]
\draw \foreach\i in {1,...,#2}{
\pgfmathsetmacro{\x}{cos(\startangle + \angle*\i)*#3}
\pgfmathsetmacro{\y}{sin(\startangle + \angle*\i)*#3}
\ifnum\i=1 \else--\fi ({\x},{\y})
};
\end{scope}
}
\begin{document}
\begin{tikzpicture}
\polygon{5}{1}
\end{tikzpicture}
\end{document}
I scraped all around the internet trying to get tips from other people's problems that could help me make this work, but I still get this error
Package tikz Error: Giving up on this path. Did you forget a semicolon?.
What point am I missing? I have no prior experience with TikZ.
UPDATE:
after making several trials I just realized my problem is somehow related to the two \pgfmathsetmacro inside the loop. Any tips on how to get this working?



standaloneclass for graphics MWEs. – Paul Gessler Apr 18 '15 at 20:49regular polygonshape without any options and then you can at least reference its anchors (.corner 1,.corner 2, ...) without the need for any calculations. — Also, look up polar coordinates. There is no need to do your own trigonometric calculations. (Hint: The syntax is(<angle>:<radius>).) — I would be interest in your goal. Maybe there are different, or even easier, ways, to do this. – Qrrbrbirlbel Apr 18 '15 at 21:58regular polygonshape. I was just not aware of its existence. What I'm really trying to do is draw a circle with a regular polygon inscribed and the same polygon circumscribed to demonstrate the Archimedes method for approximating Pi. – Mauren Apr 19 '15 at 13:02