There is a big difference between the circle and the regular polygons of the page you quoted Label Points in a circle in tikz and the one you coded.
Indeed, you have traced the regular polygon with the node
operation while the other solution builds them with the draw
operation.
To make the distinction, you have to understand what a path
is.
What is a path with TikZ?
I quote from page 119 of manual 3.0.1a:
A path is a series of straight or curved lines, which need not be
connected. TikZ makes it easy to specify paths, partly using the
syntax of METAPOST.
I quote from page 119 of manual 3.0.1a:
By default, the \path command does "nothing" with the path, it
just "throws it away". Thus, if you write \path(0,0)--(1,1);, nothing
is drawn in your picture. The only effect is that the area occupied by
the picture is (possibly) enlarged so that the path fits inside the
area. To actually "do" something with the path, an option like
draw or fill must be given somewhere on the path. Commands like \draw do this implicitly.
I quote from page 965 of manual 3.0.1a:
In pgf the most important entity is the path. All graphics are
composed of numerous paths that can be stroked (drawn), filled, shaded, or
clipped against. […] Paths are first constructed and then
used. […]
A path is first built with \path
operation. It is traced with draw
operation.
What is a node with TikZ?
I quote from page 214 of manual 3.0.1a:
Nodes are added to paths using the special path operation node. Nodes are not part of the path itself.
Rather, they are added to the picture just before or after the path has been drawn.
The node
operation is originally used to write text on the figure, next to a point. To name it for example. This text can be framed with different shapes
such as rectangle
, ellipse
circle
and with the shapes.geometry
library that you use with regular polygon
. So the node
are like a kind of embellishment of the drawing.
I quote from page 214 of manual 3.0.1a:
In the simplest case, a node is just some text that is placed at some
coordinate. However, a node can also have a border drawn around it or
have a more complex background and foreground. Indeed, some nodes do
not have a text at all, but consist solely of the background.
Since the main purpose of the node
operation is to place text next to a point, the nodes
are not modified when the figure is enlarged or reduced (It is possible, but otherwise).
By default, transformations do not apply to nodes:
I quote from page 234 of manual 3.0.1a:
It is possible to transform nodes, but, by default, transformations do
not apply to nodes. The reason is that you usually do not want your
text to be scaled or rotated even if the main graphic is transformed.
Scaling text is evil, rotating slightly less so.
Remember that a node is not part of the path and is insensitive to path transformations such as enlargements and reductions.
For example, on the following code, I coloured the circle blue. By reducing the figure, only the circle drawn with the draw
operation is reduced. The text and the regular polygon have not been reduced because they have been plotted with the node
operation.
\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw[thick,fill=blue!20](3,3) circle(4.25);
\node[ultra thick, red, draw,minimum size={2*4.25cm},regular polygon,regular polygon
sides=16] at
(3,3) (16-gon)[text=blue] {I am a hexakaidecagon};
\foreach \p [count=\n] in {H,E,X,A,K,A,I,D,E,C,A,G,O,N,E,-}{
\node [label=22.5*(3+\n):\p] at (16-gon.corner \n){};}
\begin{scope}[shift={(12,2)},scale=.3]
\draw[thick,fill=blue!20](3,3) circle(4.25);
\node[ultra thick, red, draw,minimum size={2*4.25cm},regular polygon,regular polygon
sides=16] at
(3,3) (16-gon)[text=blue] {I am a hexakaidecagon};
\foreach \p [count=\n] in {H,E,X,A,K,A,I,D,E,C,A,G,O,N,E,-}{
\node [label=22.5*(3+\n):\p] at (16-gon.corner \n){};}
\end{scope}
\end{tikzpicture}
\end{document}
Your simplified code to facilitate explanations:
\draw[thick](3,3) circle(4.25);
\node[draw,regular polygon,regular polygon sides=16] at (3,3) (16-gon) {};
You have placed a node at the point (3,3) and you have framed it by a regular polygon. You have called this node now (16-gon) as if it were a point
in the current path, but it is not a point: it remains a node
!
And as if everything wasn't complicated enough like that (to complicate things even more) TikZ allows you to name a node
and use it as if it were a point
on the current path
, which it isn't!
Name a node as if it were a point:
I quote from page 214 of manual 3.0.1a:
The node
operation is typically followed by some options, which apply
only to the node. Then, you can optionally name the node by providing
a name in parentheses. Lastly, for the node operation you must provide
some label text for the node in curly braces, while for the coordinate
operation you may not. The node is placed at the current position of
the path either after the path has been drawn or (more seldomly and
only if you add the behind path option) just before the path is drawn.
This necessarily leads to confusion: You have confused the nodes
witch are not part of the path and the points
witch are part of the path
.
You name this node (16-gon)
after enlarging it so that it fits perfectly with the circle.
As (16-gon)
is a node
, its vertices are anchors
(see page 227 of the manual). Their normal use is to allow this shape to be anchored at a point
on the path
.
What is a anchor with TikZ?
I quote from page 42 of manual 3.0.1a:
For this, every node object that you put in your picture is equipped
with several anchors. For example, the north anchor is in the middle
at the upper end of the shape, the south anchor is at the bottom and
the north east anchor is in the upper right corner. When you give the
option anchor=north, the text will be placed such that this northern
anchor will lie on the current position and the text is, thus, below
the current position.
Page 700 of the manual indicates that the vertices of a polygon with name s name=s
are named (s.corner 1)
(s.corner 2)
etc.
As you named this polygon (16-gon)
then its vertices are named (16-gon 1)
(16-gon 2)
etc.
Here is an example copied on page 700 of the manual by renaming the polygon (5-gon)
To place text (so nodes
) on the vertices of another node
(the polygon), TikZ
allows you to do this with labels
.
What is a label with TikZ?
I quote from page 239 of manual 3.0.1a:
/tikz/label=[< options >]< angle >: < text> (no default)
When this
option is given to a node operation, it causes another node to be
added to the path after the current node has been finished. This extra
node will have the text .
I add each label with an iteration to the list of labels {H,E,X,A,K,A,I,D,E,C,A,G,O,N,E,--}
by attaching them to each vertex of the polygon. Not to mention placing a small red disc on each vertex: fill=red,circle,inner sep=2pt,
\foreach \p [count=\n] in {H,E,X,A,K,A,I,D,E,C,A,G,O,N,E,--}{
\node [fill=red,circle,inner sep=2pt,label=22.5*(3+\n):\p] at (16-gon.corner \n){};}
Here is the result and the final code:
\documentclass[tikz, border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw[thick](3,3) circle(4.25);
\node[ultra thick, red, draw,minimum size={2*4.25cm},regular polygon,regular polygon
sides=16,rotate=11.25] at
(3,3) (16-gon)[text=blue] {I am a hexakaidecagon};
\foreach \p [count=\n] in {H,E,X,A,K,A,I,D,E,C,A,G,O,N,E,--}{
\node [fill=red,circle,inner sep=2pt,label=22.5*(3+\n):\p] at (16-gon.corner \n){};}
\end{tikzpicture}
\end{document}
Translated with www.DeepL.com/Translator