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.

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?

share|improve this question
    
Try put braces around the sin expression: {sin(#2)}. BTW #1 and #2 does not exist... ;) –  zeroth Jan 9 '12 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 {}). –  Andrew Stacey Jan 9 '12 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 '12 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. –  Andrew Stacey Jan 9 '12 at 19:03
add comment

marked as duplicate by Roelof Spijker, Leo Liu, percusse, lockstep, Andrew Stacey Jan 9 '12 at 19:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

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}
share|improve this answer
add comment

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