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 would like to place several groups of three objects (two circle paths and one node) in a triangular area. I came up with the following code, which is based on a subdivision of the triangle in horizontal slices and a random positioning within the slice. (used inside a tikzpicture environment in beamer, and with all the related tikz libs [calc, decorations, decorations.text, decorations.pathmorphing, shapes.callouts, shapes.symbols] loaded and working):

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc, decorations,decorations.text,decorations.pathmorphing,shapes.callouts,shapes.symbols}

\begin{document}
\begin{frame}{MWE}
\centering
\begin{tikzpicture}
\foreach \l in {1,2,...,10}
      {
          \coordinate (mycenterpoint) at (${(.5*\l+.1)*rand}*(1,0)+{rnd-\l-1}*(0,1)$);
          \coordinate (myangle) at (rand*180:1.4pt);
          %\node[starburst,fill=cyan,fill opacity=0.3] at (mycenterpoint) {};
          \fill[red] (mycenterpoint) ++(myangle) circle (2pt);
          \fill[green] (mycenterpoint) ++($-1*(myangle)$) circle (2pt);
      }
\end{tikzpicture}
\end{frame}
\end{document}

which places as I expected the red and green circles, namely in a random position in the respective triangle slice. Unfortunately, if i uncomment the starburst line, something in the rand is jeopardized, and all the circles and nodes are placed on a "line" just as the rand and rnd in the first coordinate definition were set to -1 and 0 respectively.

does anyone have hints on how and where the rand function gets spoiled?

share|improve this question
    
Welcome to TeX.sx! –  lockstep Dec 11 '12 at 12:19
    
Could you turn the code snippet into a full minimal example document, so starting from \documentclass? That makes it much easier for others to try out the code to come up with a solution. –  Jake Dec 11 '12 at 12:51
    
done. there are still "locally" useless tikzlibraries which i need in other slides. –  davide Dec 11 '12 at 12:57
    
I believe the problem comes with the choice of the shape: if you use cloud, you won't have problems. Causes of such an issue are mysterious to me... –  Claudio Fiandrino Dec 11 '12 at 15:11
    
@ClaudioFiandrino : it looks like the starburst shape resets the seed internally somehow. I found out a way to overcom this, but it's not realy "clean" –  davide Dec 11 '12 at 16:05

1 Answer 1

I somehow found out that setting a loop-variable dependent random seed does the trick. Something like:

\pgfmathsetseed{\l}
\coordinate (mycenterpoint) at (${(.5*\l+.1)*rand}*(1,0)+{rnd-\l-1}*(0,1)$);
\coordinate (myangle) at (rand*180:1.4pt);
\node[starburst,fill=cyan,fill opacity=0.3] at (mycenterpoint) {};

in place of the first three lines in the \foreach loop in the example above.

The problem comes along with the starburst shape, as @ClaudioFiandrino suggested, which apparently resets the seed internally. I think there should be some cleaner way to achieve the same though I have no clue how to obtain it

share|improve this answer
    
Do you want to keep the current seed? I think I know where it is reset but I don't know what you want to keep. –  percusse Dec 11 '12 at 16:11

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.