7

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}
\usetikzlibrary{calc,fadings,decorations.pathreplacing}


\begin{document}
\begin{tikzpicture}
  \def\nuPi{3.1459265}
  \foreach \i in {11,10,...,0}{
    \foreach \j in {5,4,...,0}{
      \shade[ball color=red] (#1,sin(#2)) circle(0.45);
    }
  }

\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?

4
  • 1
    Try put braces around the sin expression: {sin(#2)}. BTW #1 and #2 does not exist... ;)
    – nickpapior
    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.
    – percusse
    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

1 Answer 1

9

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}
  \def\nuPi{3.1459265}
  \foreach \i in {11,10,...,0}{
    \foreach \j in {5,4,...,0}{
      \shade[ball color=red] (\i,{sin(\j)}) circle(0.45);
    }
  }
\end{tikzpicture}

Not the answer you're looking for? Browse other questions tagged .