Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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{minimal}
\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}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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