Drawing a regular polygon encompassed by a circle

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


Just another way with TikZ.

It is possible to use more styles and have a more flexible setup (you cannot use a or c more than once without drawing it only once). It is possible to draw ellipses by using the x radius and y radius key.

I don’t like the the implementation via \nodeRot (could just as well be a key). But that’s the easiest way to allow rotations of the polygon with the rotate key and correctly placed labeling of the corners without rotated nodes and without using PGF tricks.

Code

\documentclass[tikz]{standalone}
\tikzset{declare function={angleForPoly(\i,\n,\d)=360/\n*\i+\d;
                           x_radius              =\pgfkeysvalueof{/tikz/x radius};
                           y_radius              =\pgfkeysvalueof{/tikz/y radius};},
  d/.style={circle,fill,outer sep=1pt,inner sep=+0pt,minimum size=+3pt,#1},
  c/.style={insert path={(C) edge[#1,to path={circle[]}] ()}},
  a/.style={insert path={(C)+(left:x_radius+.5cm) edge[#1,<->] +(right:x_radius+.5cm)
                         (C)+(  up:y_radius+.5cm) edge[#1,<->] +( down:y_radius+.5cm)}}}
\def\nodeRot{0}
\newcommand*\poly[2][]{%
  \path (0,0) coordinate (C) [rotate/.append code={\def\nodeRot{##1}},#1]
  ++ ({angleForPoly(0,#2,0)}:x_radius and y_radius) coordinate[d] (c)
   \foreach \cnt[count=\Cnt from 0] in {1,...,#2} {
      (c) [late options={alias=c'}] edge [<-, thick] (C)
      coordinate[d] (c) at ({angleForPoly(\cnt,#2,0)}:x_radius and y_radius)
      (c') edge[dashed] (c)
      \ifnum\Cnt>0 node[anchor={angleForPoly(\Cnt,#2,180+\nodeRot)},circle]
        {$\omega\ifnum\Cnt>1^{\Cnt}\fi_{#2}$} \fi
   };}
\begin{document}
\begin{tikzpicture}[radius=2cm,>=latex]
\matrix {
  \poly[a,c]{3} & \poly[a=red,c,rotate=30]{4} & \poly {5} \\
  \poly[c]  {6} & \poly                   {7} & \poly {8} \\
  \poly     {9} & \poly                  {10} & \poly{11} \\
};
\end{tikzpicture}
\end{document}

Output

enter image description here


with PSTricks:

\documentclass{article}
\usepackage{pstricks-add}
\usepackage[margin=5mm]{geometry}
\pagestyle{empty}\parindent=0pt
\begin{document}

\psset{unit=2}
\multido{\iA=3+1}{20}{%
  \begin{pspicture}(-1.3,-1.3)(1.3,1.3)
  \degrees[\iA]\pscircle{1}% set unit for a circle to 3,4,5,... instead of 360
  \psaxes[labels=none,ticks=none](0,0)(-1.1,-1.1)(1.1,1.1)
  \multido{\iB=0+1,\iC=1+1}{\iA}{%
    \psline[linestyle=dashed,showpoints](1;\iB)(1;\iC)
    \psline[arrowscale=2,linewidth=1pt]{->}(1;\iB)
    \rput(1.15;\iB){$\omega_{\iA}^{\iC}$}}
  \end{pspicture} }

\end{document}

enter image description here