# Using sin inside of tikz \foreach [duplicate]

Possible Duplicate:
Problems with TikZ calculations

I am trying to generate a surface in tikzpicture environment. The surface is composed of spheres so I have created this:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\def\nuPi{3.1459265}
\foreach \i in {11,10,...,0}{
\foreach \j in {5,4,...,0}{
}
}

\end{tikzpicture}
\end{document}


Which is supposed to give some nice undulation to the surface. However, when I run this I get the dreaded

! Package tikz Error: Giving up on this path. Did you forget a semicolon?.

How can generate the undulation then?

• Try put braces around the sin expression: {sin(#2)}. BTW #1 and #2 does not exist... ;) Jan 9, 2012 at 14:15
• I get compilable code with braces around the sin(..) as zeroth says and replacing #1 by \i and #2 by \j. However, the variation is so small that the result is just a line of spheres! The braces are needed to protect the ) of sin(..) from being interpreted as the closing parenthesis of the coordinate (there's no error checking on () as there is with {}). Jan 9, 2012 at 14:24
• You don't need to define a pi just use the r parameter to let TikZ know about it. Check the manual page 526. Jan 9, 2012 at 14:44
• We've closed this as a duplicate because the actual problem (the parenthesis) is already contained in another question and we want to make it easy for others to find their answers quickly rather than having to read through several similar questions. Jan 9, 2012 at 19:03

TikZ is confused by the parentheses of (x,sin(y)) so put the sin-part in braces {} and use foreacht correctly (i.e. \i and \j instead of #1 and #2):
\begin{tikzpicture}