# Connecting points in a for loop with tikz

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{center}
\begin{tikzpicture}[line width=0.5pt]
\foreach \i in {0,30,...,360} {--(\i:2.8) node{$\bullet$}};
\foreach \angle [count=\xi] in {60,30,...,-270}
{\draw[line width=1pt] (\angle:2.8cm) -- (\angle:3cm);
\node[font=\large] at (\angle:2.2cm) {\xi};}
\foreach \angle in {0,90,180,270};
\foreach \angle in {60,30,...,-270}
{\draw[fill=black] (\angle:2.8cm) circle (0.1pt);
}
\end{tikzpicture}
\end{center}
\end{document}


This code produces

Following the code given in the answers I managed to produce and connect all the dots in a clock. Now there is one additional line from number 3 (or 90:2.8 I suppose) to the center of the clock which I don't want. You can see it clearly in the diagram. Why is it coming and how to remove it?

• Have a look at /pgf/foreach/remember. Feb 15, 2020 at 14:18
• So I added \foreach \angle [remember=\angle as \xyz] in {60,30,...,-270} this to the code on the relevant line, still I have to start a line from one point and end it at another, how code this? Feb 15, 2020 at 14:52
• You can set the initial value with initially: \foreach \angle [remember=\angle as \lastangle (initially 90)] in {60,30,...,-270} {\draw[fill=black] (\angle:2.8cm) circle[radius=1pt]; \draw (\lastangle:2.8cm) -- (\angle:2.8cm); }
– user194703
Feb 15, 2020 at 15:12

Update: the clock as updated question.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[cyan]
\draw (0:2.8) \foreach \i in {0,30,...,360} {--(\i:2.8) node{$\bullet$}};
\foreach \i [count=\xi] in {60,30,...,-270}
\draw[thick] (\i:2.8)--(\i:3) (\i:2.2) node[scale=1.2,orange]{\xi};
\draw[line width=2pt] (0,0) circle(3);
\end{tikzpicture}
\end{document}


Here is a way:

\documentclass[tikz,border=0.5cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle(3) (0:2.8) \foreach \i in {0,30,...,330} {--(\i:2.8) node{$\bullet$}}--cycle;
\end{tikzpicture}
\end{document}

• Have a look at this code. I don't want the line connecting the center and number 3. This is what I exactly wanted to achieve, but as it wasn't minimal I shortened it to the code given above. Feb 16, 2020 at 15:21
• @Niranjan Now I know you want to draw a clock,but honestly I don't not get your point. Can you add a picture on your question? Feb 16, 2020 at 15:46
• Yes. Please check the edit. Feb 16, 2020 at 15:57
• @Niranjan Is it what you want? \documentclass[tikz,border=3mm]{standalone} \begin{document} \begin{tikzpicture} \draw (0:2.8) \foreach \i in {0,30,...,360} {--(\i:2.8) node{$\bullet$}}; \foreach \i [count=\xi] in {60,30,...,-270} \draw[thick] (\i:2.8)--(\i:3) (\i:2.2) node[scale=1.2]{\xi}; \draw[line width=2pt] (0,0) circle(3); \end{tikzpicture} \end{document} Feb 16, 2020 at 16:16
• Yes exactly this is what I want :) Thank you so much. Feb 16, 2020 at 16:57

Another way with tkz-euclide

The clock:

\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}[scale=2,ms/.style={teal,line width=.8mm}]
\foreach \an [count=\i] in {60,30,...,-270}
{ \tkzDefPoint(\an:2.8){\i}
\tkzDrawSegment[ms]({\an:2.8},{\an:3})}
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R,teal,line width=1.6mm](O,3 cm)
\tkzDrawPolygon[ms](1,...,12)
\tkzDrawPoints[teal,size=6](1,...,12)
\tkzAutoLabelPoints[purple,font=\Large,center=O,dist=-0.1](1,...,12)
\end{tikzpicture}
\end{document}


\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}

\begin{tikzpicture}
\foreach \an [count=\i] in {0,30,...,360}
{ \tkzDefPoint(\an:2.8){A_\i}}
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,3 cm)
\tkzDrawPolygon(A_1,A_...,A_12)
\tkzDrawPoints(A_1,A_...,A_12)
\end{tikzpicture}
\end{document}