I would like to draw some vector fields on a triangle, and I am using nested \foreach
loop to do that, however in the inner loop, you can't use the outer loop variable as the numeric range. For e.g. The following code does not work:
\begin{tikzpicture}
{\draw (0,0) -- ++(1,0) -- ++(-1,1) -- cycle;}
\foreach \x in {0,0.1,...,1}
\foreach \y in {0,0.1,...,1-\x}
{
\draw [->] (\x,\y)--(-1 + \x + 2*\y,-\y);
}
\end{tikzpicture}
Is there a way to do nested loop like this? Or I have to manually go through the loop for each \y
which is \x
dependent?
\x
is0
the inner loop is{0,0.1,...,0}
and then processes the0.1
as well. Your drawing code seems just not right. You might also want to use integers instead, i.e.{0,1,...,10}
and then use\x/10
to avoid rounding issues with the loop variables.\x
, for e.g.,1-\x
, sorry for the confusion