1

I am trying to make a clock with the tkz-euclide package using a for loop. I have tried to get it to work but it keeps giving me errors. Here is my MWE

\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
%\usetikzlibrary{calc}
\begin{document}
  \begin{tikzpicture}
    \def \radius{5cm}
    \def \n{12}
    \tkzDefPoint(0,0){O}
    \tkzDrawCircle[R](O,\radius)
  %  \tkzDefPoint(90-360/12:5){B}
  %  \tkzDefPoint(90-360/12:4){C}
  %  \tkzDrawSegment(B,C)
  %  \tkzLabelPoint[below](C){1}
  %  \tkzDrawPoint(B)
  \foreach \i in {1,...,\n}
  {
  \tkzDefPoint(90-1*(360/\n):\radius){t_\i}
  \tkzDrawPoint(t_\i)
  }
  \end{tikzpicture}
\end{document}

It seems to be having problems understanding the angle in the \tkzDefPoint command. Any suggestions?

1 Answer 1

4

The error you get is ! FP error: Illegal character c found in float number!.. The c in question is that in 5cm. Looks like you need a unitless number here, so remove cm from the definition of \n. You need to add it back in \tkzDrawCircle though.

And of course you want to multiply by \i not 1 in the loop.

\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
%\usetikzlibrary{calc}
\begin{document}
  \begin{tikzpicture}
    \def \radius{5}
    \def \n{12}
    \tkzDefPoint(0,0){O}
    \tkzDrawCircle[R](O,\radius cm)
  %  \tkzDefPoint(90-360/12:5){B}
  %  \tkzDefPoint(90-360/12:4){C}
  %  \tkzDrawSegment(B,C)
  %  \tkzLabelPoint[below](C){1}
  %  \tkzDrawPoint(B)
  \foreach \i in {1,...,\n}
  {
  \tkzDefPoint(90-\i*360/\n:\radius){t_\i}
  \tkzDrawPoint(t_\i)
  }
  \end{tikzpicture}
\end{document}

enter image description here

2
  • Thank you, I was wondering if I needed to use parenthesis in expressions for coordinates what are some tips to avoid the parser from freaking out. I vaguely recall in some cases you use {} to enclose something more complicated.
    – 1028
    Aug 1, 2016 at 19:26
  • @1028 If you need parentheses in the calculation, for example if you have sin(x) or (a+b)/2, then you need braces as well. The reason is that when reading a coordinate (x,y), the parser typically looks for the closing parenthesis, so a parenthesis in one of the coordinates will mess things up. Aug 1, 2016 at 19:30

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.