0

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).

  • If you don't want to calculate tick lengths, use polar coordinates. – user156344 Mar 30 at 17:12
  • @JolueV that is a manual calculation as well where there is a chance for error or miscalculation. – subham soni Mar 30 at 17:14
1

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.

  • can you explain the code in the for loop as well please – subham soni Mar 30 at 17:27
  • @subhamsoni I added some explanations. – user156344 Mar 30 at 17:32
  • what is \draw (\i:5) -- (\i:4.5) – subham soni Mar 30 at 17:35
  • @subhamsoni It draws a line joining point (\i:5) and point (\i:4.5); all of them are polar coordinates. Point (x:y) is defined like this. – user156344 Mar 30 at 17:41
0

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

  • the ticks need to be inside like in an alarm clock or watch – subham soni Mar 30 at 17:17
  • Also can you explain technically the code in the for loop – subham soni Mar 30 at 17:18
  • @subhamsoni I added inwards ticks and an explanation. – user121799 Mar 30 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.