Label Points in a circle in tikz
As a typical counterpart to tikz
drawings, here's a take on the pstricks
version.
\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pst-node
\usepackage{multido}% http://ctan.org/pkg/multido
\begin{document}
\begin{pspicture}(10,10)
\SpecialCoor
\psset{unit=3cm,runit=3cm}% Scaling of x,y and r units
\pnode(3,0){O}% Circle origin
\pscircle(O){1}% Outer circle
\degrees[20]% 20 angles per 360 degrees (each angle is 18 degrees)
\rput(O){\multido{\i=1+1}{20}{% Cycle through 20 angles and relocate relative to circle origin
\pcline(O)(1;\i)% Print line from origin to circle edge
\uput{5pt}[\i]{\i}(1;\i){\i}% Print label with rotation
}}
\end{pspicture}
\end{document}
Modifying the label command to
\uput{5pt}[\i]{0}(1;\i){\i}% Print label without rotation
yields
Printing labels at for every odd index is possible by using
\ifodd\i\uput{5pt}[\i]{\i}(1;\i){\i}\fi% Print ODD label with rotation
while
\ifodd\i\else\uput{5pt}[\i]{\i}(1;\i){\i}\fi% Print EVEN label with rotation
prints only even indices. Here's an illustration of the latter (print EVEN labels with rotation) choice:
This can be combined with no rotation of every node as well. For this modify the appropriate parameter in the \uput
command, which is defined by
\uput{<labelsep>}[<refangle>]{<rotation>}(<coordinate>){<stuff>}
This rotates <stuff>
by angle <rotation>
at distance <labelsep>
and angle <refangle>
from <coordinate>
. In my example, using \degrees[<n>]
divides 360 degrees into <n>
angles. So, it allows you to use these angles (as numbers, where angle=i*(360/<n>)
). Also, because of \SpecialCoor
, one can use polar coordinates - represented by (<r>;<t>)
- or Cartesian coordinates - represented by (<x>,<y>)
. pst-node
allows for substituting any of these <coordinate>
types with a node <name>
defined by (say) \psnode(<coordinate>){<name>}
, as was done in the MWE.
A friend of mine once needed kind of a cake to visualize fractions. Adding rotated nodes wasn't hard:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}
\newcommand{\TikZFractionalCake}[5]{% Num, Denom, Color, Borders, Size
\pgfmathsetmacro{\angle}{360/#2};%
\foreach \x in {1,...,#1}%
{ \pgfmathsetmacro{\lox}{\x-1}%
\filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
\pgfmathsetmacro{\mix}{\x-0.5}%
\node[rotate=\mix*\angle] at (\mix*\angle:#5+0.3) {\x};
}
}
\begin{document}
\begin{tikzpicture}
\TikZFractionalCake{20}{20}{white}{black}{3}
\end{tikzpicture}
\end{document}
Sure, makes it even easier:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}
\newcommand{\TikZFractionalCake}[5]{% Num, Denom, Color, Borders, Size
\pgfmathsetmacro{\angle}{360/#2};%
\foreach \x in {1,...,#1}%
{ \pgfmathsetmacro{\lox}{\x-1}%
\filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
\node[rotate=\x*\angle] at (\x*\angle:#5+0.3) {\x};
}
}
\begin{document}
\begin{tikzpicture}
\TikZFractionalCake{20}{20}{white}{black}{3}
\end{tikzpicture}
\end{document}
That is possible indeed:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections, calc, fpu, decorations.pathreplacing}
\newcommand{\TikZFractionalCake}[6]{% Num, Denom, Color, Borders, Size, k-th label
\pgfmathsetmacro{\angle}{360/#2};%
\foreach \x in {1,...,#1}%
{ \pgfmathsetmacro{\lox}{\x-1}%
\filldraw[draw=#4,fill=#3] (0,0) -- (\angle*\lox:#5) arc (\angle*\lox:\angle*\x:#5) -- cycle;%
}
\pgfmathsetmacro{\secondstep}{2*#6}
\pgfkeys{/pgf/number format/.cd,int detect,precision=2}
\foreach \x in {#6,\secondstep,...,#1}%
{ \node[rotate=\x*\angle] at (\x*\angle:#5+0.3) {\pgfmathprintnumber{\x}};
}
}
\begin{document}
\begin{tikzpicture}
\TikZFractionalCake{21}{21}{white}{black}{3}{3}
\end{tikzpicture}
\end{document}
You have several solutions :
1) you can mix tkz-euclide with tikz
\documentclass{minimal}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=1]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,3 cm)
\def\sectors{20}
\foreach \i in {1,2,...,\sectors} {
\tkzDefPoint({\i*360/\sectors}:3){P\i}
\tkzDrawSegment[color=black](O,P\i)
\node[label=18*\i:\i] at (P\i) {} ;
}
\end{tikzpicture}
\end{document}
\end{document}
3) you use only tikz ! (see Tom' solution)
4) I forgot this one ( I have some difficulties to work with my personal packages).
I put like you scale=3
but when it's possible I avoid the use of scale
.
\documentclass{minimal}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=3]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,1 cm)
\def\sectors{20}
\tikzset{label style/.style={} };
\foreach \i in {1,2,...,\sectors} {
\tkzDefPoint({\i*360/\sectors}:1){P\i}
\tkzDrawSegment[color=black](O,P\i)
\tkzLabelPoint[label=360/\sectors*\i:\i](P\i){}
}
\end{tikzpicture}
\end{document}
5) It's possible to place the label on the radius but I think it's not a good typographic idea
\documentclass{minimal}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=3]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,1 cm)
\def\sectors{20}
\tikzset{label style/.style={} };
\foreach \i in {1,2,...,\sectors} {
\tkzDefPoint({\i*360/\sectors}:1){P\i}
\tkzDrawSegment[color=black](O,P\i)
}
% it's possible to avoid the next loop with conditional macro ...
\foreach \i in {1,3,...,\sectors} {% you can change what you want here
\tkzLabelPoint[rotate=18*\i,right](P\i){\i} ;
}
\end{tikzpicture}
\end{document}