4

I want to draw a circle using tkz-euclide and n segments of this circle. Since I want to have n as a basic variable I need to divide in the following example. However it doesn't work, any ideas?

\documentclass{standalone}
\usepackage{tkz-euclide}
\usepackage{tkz-base}
\usepackage{color}
\usepackage{calc}
\begin{document}


\begin{tikzpicture}[scale=3]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,1 cm)
\def\sectors{20}
\foreach \i in {0,(360:\sectors),...,360}{
\tkzDefPoint({cos(\i*\FPpi/180)},{sin(\i*\FPpi/180)}){P}
\tkzDrawSegment[color=black](O,P)
%\tkzDrawPoint(P)
}

\end{tikzpicture}


\end{document}
2

I would write it in the following way (using the (angle:radius) syntax for polar coordinates).

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

\begin{tikzpicture}[scale=3]
\tkzDefPoint(0,0){O}
\tkzDrawCircle[R](O,1 cm)
\def\sectors{20}
\foreach \i in {1,2,...,\sectors} {
    \tkzDefPoint({\i*360/\sectors}:1){P\i}   
    \tkzDrawSegment[color=black](O,P\i)
    \tkzDrawPoint(P\i)
}

Using P\i as the node name ensures that the points have different names, so that you can access them later on (giving all the same name would work for just this picture, because names just get overwritten).

Alternatively, you can set the point with

\tkzDefPoint({cos(\i*2*pi/\sectors)},{sin(\i*2*pi/\sectors)}){P\i}

There is one inconsistency to be aware of: Standard TikZ/PGF trigonometric functions take degrees. If you use them in tkz commands, they take radians. And polar coordinates are always specified in degrees, even in tkz.

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.