How do I correctly reference a value calculated using a \pgfmathsetmacro definition when defining the check condition of an \ifthenelse statement?
Example Problem; Randomly scattering nodes within a circle…
Using {1>0.5} as my \ifthenelse check condition, the following Tikz picture plot works as expected;
\documentclass{standalone}
\usepackage{ifthen, tikz, pgfplots} \usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,...,10}{
\pgfmathsetmacro{\r}{random()}
\pgfmathsetmacro{\theta}{random()*360}
\pgfmathsetmacro{\weight}{random()}
\pgfmathsetmacro{\x}{\r*sin(\theta)}
\pgfmathsetmacro{\y}{\r*cos(\theta)}
\ifthenelse{1>0.5}{\node[circle, inner sep=1pt, fill=black] (\i) at (\x,\y) {};}{}
}
\end{tikzpicture}
\end{document}
But I have no such luck when considering the loop dependant \ifthenelse check condition {\weight>0.5} below;
\documentclass{standalone}
\usepackage{tikz, pgfplots} \usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,...,10}{
\pgfmathsetmacro{\r}{random()}
\pgfmathsetmacro{\theta}{random()*360}
\pgfmathsetmacro{\weight}{random()}
\pgfmathsetmacro{\x}{\r*sin(\theta)}
\pgfmathsetmacro{\y}{\r*cos(\theta)}
\ifthenelse{\value{\weight}>0.5}{\node[circle, inner sep=1pt, fill=black] (\i) at (\x,\y) {};}{}
}
\end{tikzpicture}
\end{document}
Is this a syntax error, or something more complicated? I can't for the life of me figure out why this won't compile properly…
Best Answer
Since no further ideas seem to be readily forthcoming, I'll convert percusse's comment (above) into an accepted answer, and close this question...
[All credit to percusse]