[Tex/LaTex] Make a polygon with automatically labelled nodes according to their coordinates

automationlabelsnodestikz-pgf

The goal: Make a polygon (and a circle containing that polygon at the nodes of the polygon, without the polygon's lines) with automatically numbered nodes according to their coordinates (x,y) [which latex must calculate] or unique names.

[EDIT: I have added a different MWE (Ignasi's), to clarify, since it does away with two macros in my old MWE at expense of one option. In this example: how does one control the size of the dots on the nodes [the option lost], and to make (x,y) coordinate positions of the nodes their visible labels, as per title of the question?]

Of course,

\node (n1) at (x,y) {$1$};

or

\node (n1) at (x,y) {$\boldsymbol{W_1(z)}$};

or

\node (n1) at (x,y) {$(x,y)$};

could be done manually on top any figure otherwise made but for more many nodes makes for long code and lots of guessing where (x,y) the nodes on the circle or polygon actually are.

!!! The labels should preferably all be away from the lines of the nodes, like here: Drawing a regular polygon encompassed by a circle

MWE(Ignasi):

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[scale=1]
\foreach \a in {4,...,5}
{
\draw[blue, solid, line width = 1mm] (\a*7,0) circle(3cm);
\node[regular polygon,
    regular polygon sides=\a,
    minimum size=6cm,
    draw] at (\a*7,0) (A) {};
\foreach \i in {1,...,\a}
    \node[circle,
    label=above:{$w_\i(z)$},
    fill=red] at (A.corner \i) {};
}
\end{tikzpicture}

\end{document}

MWE(old):

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

%POLYGON command
\newcommand{\polygon}[2]{%
let \n{len} = {2*#2*tan(360/(2*#1))} in
++(0,-#2) ++(\n{len}/2,0) \foreach \x in {1,...,#1} { -- ++(\x*360/#1:\n{len})}}

%DOTS command
\makeatletter
\tikzset{
    dot diameter/.store in=\dot@diameter,
    dot diameter=3pt,
    dot spacing/.store in=\dot@spacing,
    dot spacing=7pt,
    dots/.style={
    line width = \dot@diameter,
    line cap = round,
    dash pattern = on 0pt off \dot@spacing}
        }\makeatother

%BEGIN

\begin{tikzpicture}
\node (n1) at (-2,-2) {$\boldsymbol{0}$};

\draw[black, dot diameter=3pt, dot spacing=40pt, dots] (0,0) circle (2);
\draw[black, solid, line width=0.5mm] (5,0) \polygon{9}{2};
\draw[black, solid, line width=0.5mm] (10,0) circle (2);
\end{tikzpicture}

%figure out how to automatically number nodes

\end{document}

Best Answer

Next is an example from page 177 on pgfmanual with some little additions

\documentclass[tikz, margin=5pt]{standalone}

\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}
\foreach \a in {3,...,7}{
\draw[blue, dashed] (\a*4,0) circle(1.5cm);
\node[regular polygon, regular polygon sides=\a, minimum size=3cm, draw] at (\a*4,0) (A) {};
\foreach \i in {1,...,\a}
    \node[circle, label=above:\i, fill=red] at (A.corner \i) {};
}
\end{tikzpicture}

\end{document}

enter image description here

Update

Next code show how to draw or undraw regular polygons defined with \node[regular polygon,..., it also show how you can cusomize corner marks and print corner coordinates.

Code for coordinates printing was take from Paul Gaborit's answer and from Torbjørn T. suggested question.

\documentclass[tikz, margin=5pt]{standalone}

\usetikzlibrary{shapes.geometric,positioning}

\makeatletter
\newcommand\xcoord[2][center]{{%
    \pgfpointanchor{#2}{#1}%
    \pgfmathparse{\pgf@x/\pgf@xx}%
    \pgfmathprintnumber{\pgfmathresult}%
}}
\newcommand\ycoord[2][center]{{%
    \pgfpointanchor{#2}{#1}%
    \pgfmathparse{\pgf@y/\pgf@yy}%
    \pgfmathprintnumber{\pgfmathresult}%
}}
\makeatother

\begin{document}

\pgfkeys{/pgf/number format/.cd,fixed,fixed zerofill,precision=2}
\tikzset{dot/.style={circle,fill=blue,minimum size=3pt, inner sep=0pt},
         square/.style={rectangle,fill=red,minimum size=4pt, inner sep=0pt,%    
                    rotate=30,anchor=center},%
        mytext/.style={anchor=north,text width=3cm,align=center}
    }

\newcommand{\labelcorner}[2][]{%
    \coordinate (aux) at (#2);
    \node[#1] at (aux) {(\xcoord{aux},\ycoord{aux})}}

\begin{tikzpicture}

\node[regular polygon, regular polygon sides=9, minimum size=3cm] (A) {};
\foreach \i in {1,...,9}
    \node[dot] at (A.corner \i) {};
\node[mytext, below=of A.south] {non drawn nonagon};

\node[regular polygon, regular polygon sides=9, minimum size=3cm, right=3cm of A, rotate=15,draw, anchor=center] (B) {};
\foreach \i in {1,...,9}
    \node[square] at (B.corner \i) {};
\node[mytext, below=of B.south] {drawn nonagon with squared dots in each corner};

\node[regular polygon, regular polygon sides=5, minimum size=3cm, right=4cm of B.center, rotate=25, anchor=center] (C) {};
\draw[thick,purple] (C.corner 1)--(C.corner 2)--(C.corner 3)--(C.corner 4);
\draw[dashed,blue] (C.center) circle (1.5cm); 
\foreach \i in {1,...,5}
    \node[square, green] at (C.corner \i) {};
\node[mytext, below=of C.south] {partially drawn pentagon with circumscribed circle};

\labelcorner[above]{A.corner 1};

\labelcorner[below left,font=\tiny]{B.corner 4};
\end{tikzpicture}
\end{document}

enter image description here