[Tex/LaTex] Drawing a regular polygon encompassed by a circle

diagramstikz-pgf

I would like to replicate the sort of diagrams shown below – a regular polygon in dashed lines encompassed by a solid lined unit circle with vectors going from the origin to each labelled vertex in an xy-plane. How would one go about doing this in TikZ?
enter image description here

Best Answer

With TikZ

\def\deg{120}                   % for triangle      
\def\p{3}                       % vertices
\begin{tikzpicture}[scale=2]
\draw [<->] (-1.5,0)--(1.5,0);
\draw [<->] (0,-1.5)--(0,1.5);
\draw (0,0) circle (1);

\foreach \t/\x in {0/0*\deg,1/1*\deg, 2/2*\deg}
{\draw[thick,->] (0:0)--(\x:1) node [] (\t) at (\x:1){};
\node[anchor=center] at (\x:1.2) {$w^{\t}_\p$};}

\foreach \from/\to in {0/1,1/2,2/0}
{\draw [thin, dashed] (\from) -- (\to);}

\end{tikzpicture}

\def\deg{40}                    % for convex hull, phase angle  
\def\p{9}                       % vertices
\begin{tikzpicture}[scale=2]
\draw [<->] (-1.5,0)--(1.5,0);
\draw [<->] (0,-1.5)--(0,1.5);
\draw (0,0) circle (1);
\foreach \t/\x in {0/0*\deg, 1/1*\deg, 2/2*\deg, 3/3*\deg, 4/4*\deg, 5/5*\deg,
6/6*\deg, 7/7*\deg, 8/8*\deg}
%\foreach \t[evaluate=\t as \x using int(\t*\deg)] in {0,1,...,8} % suggested by Claudio Fiandrino
{\draw[thick,->] (0:0)--(\x:1) node[] (\t) at (\x:1) {};
\node[anchor=center] at (\x:1.2) {$w^{\t}_\p$};}
\foreach \from/\to in {0/1, 1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/0}
{\draw [thin, dashed] (\from) -- (\to);}
\end{tikzpicture}

This is the result

enter image description here

Related Question