I tried to plot integer points that fall into a 2D region that's dynamically changed. So I resort to Cases
and Select
, but Cases
with Condition
is not working expectedly. Here is the simplifed version of my code and result:
region[u_] := u <= x + y <= u + 2;
intPoints = Flatten[Table[{x, y}, {x, 0, 13}, {y, 0, 13}], 1];
Manipulate[
Column[{
{ListPlot[intPoints],
RegionPlot[region[u], {x, 0, 13}, {y, 0, 13}]},
{ListPlot[Cases[intPoints, {x_, y_} /; region[u]]],
ListPlot[Cases[intPoints, {x_, y_} /; Evaluate[region[u]]]],
ListPlot[Select[intPoints, region[u] /. {x -> #[[1]], y -> #[[2]]} &]]}}],
{u, 0, 13}
]
I don't understand why inside Cases
the point coordinates x and y won't go into region for the Condition
to be evaluated. Does it first do the replacement of x and y and then do the evaluation? But why the additional Evaluate
operation still doesn't help?
Could someone elaborate me on this? Thanks.