1

Referring to the question How to make add tick to node in tikz, how do I extend this to a circle shape in TikZ.

A simple approach is to draw lines as ticks by calculating the coordinates. Sample approach below:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\filldraw (a.center) circle [radius=0.1cm];
\draw ($(a.center)-(4.5,0)$) -- (a.west);
\draw ($(a.east)-(0.5,0)$) -- (a.east);
\end{tikzpicture}
\end{document} 

enter image description here

But, this approach is not effective, as the ticks length has to calculated manually.

Is there a better approach to do this (ticks in the circle would be like the lines on an alarm clock, which are inclined execept at 12, 3, 6 and 9 numbers).

subham soni
  • 9,673

2 Answers2

3

Use \foreach and polar coordinates (with care of course) you can have this

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\filldraw (a.center) circle [radius=0.1cm];
\foreach \i [count=\j] in {60,30,...,-270} {
    \draw (\i:5) -- (\i:4.5);
    \draw (\i:4.2) node[font=\large] {\j};
}
\end{tikzpicture}
\end{document} 

enter image description here

In this code, the for loops iterates through the set {60, 30, 0, −30, −60, −90, −120, −150, −180, −210, −240, −270}. Each of these numbers is the angle of the "ticks". I use polar coordinate based on these iterators, so the angles of the "ticks" are accurate.

I set a counter for the for loop (\j) to add numbers to the picture.


\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\filldraw (a.center) circle [radius=0.1cm];
\foreach \i [count=\j] in {60,30,...,-270} {
    \draw (\i:5) -- (\i:4.5);
    \draw (\i:4.2) node[font=\large] {\j};
}
\foreach \i in {84,78,...,-270} \draw (\i:5) -- (\i:4.8);
\end{tikzpicture}
\end{document} 

enter image description here

The second for loop is to draw smaller ticks. 84, 78, etc. are the angles of these ticks.

1

Something like that?

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\filldraw (a.center) circle [radius=0.1cm];
\draw ($(a.center)-(4.5,0)$) -- (a.west);
\draw ($(a.east)-(0.5,0)$) -- (a.east);
\foreach \X in {0,10,...,350}
{\draw (a.\X) -- ++ (\X:0.2);}
\end{tikzpicture}
\end{document} 

enter image description here

OK, inside.

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\filldraw (a.center) circle [radius=0.1cm];
\foreach \X in {0,10,...,350}
{\draw (a.\X) -- ++ (180+\X:0.2);}
\end{tikzpicture}
\end{document} 

enter image description here

\foreach \X in {0,10,...,350} loops over \X in {0,10,...,350}, and then the nodes have anchors given in degrees, so (a.\X) is a point at the boundary of a at the angle \X. This syntax is mentioned in my previous answer to one of your questions. ++ (\X:0.2) adds some shift in polar coordinates, \X is the angle and 0.2 the radius. To have the ticks inwards, we need to add 180 degrees to \X (one could also use (\X:-0.2).)

And just for fun: a watch.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\node[circle,draw,minimum size=10cm] (a) at (0,0) {};
\filldraw (a.center) circle [radius=0.1cm];
\foreach \X in {1,...,12}
{\draw (a.-\X*30+90) -- ++ (270-\X*30:0.3) node[pos=1.5]{\X};}
\end{tikzpicture}
\end{document} 

enter image description here