[Tex/LaTex] How to draw several polygons on the same base line using TikZ

foreachgeometryloopsprogrammingtikz-pgf

I want to construct a figure that will be symmetrical polygons on the same base.

So, there is an equilateral triangle, a square, a pentagon, a hexagon, etc. one side of all these is the same horizontal line of, say, 5 c.m.

The brute force method I can think of is actually calculate the coordinates of different vertices and just draw lines in tikz.

But I am sure, (I hope, at least) that there is a more elegant, programatic way of doing the same thing.

Something like for i = 1 to n, etc.

But given my limited experience with tikz, I am not even able to dream it.

Any suggestions, help, pointers?

Best Answer

As a single path:

\documentclass[tikz,border=5]{standalone}
\begin{document}
\tikz\draw (0,0) \foreach \i in {3,...,10}
  \foreach \j in {1,...,\i}{ -- ++(360/\i*\j:1) };
\end{document}

enter image description here

Related Question