# How to extract certain plot points from a plot with a grid?

I have created a plot using the code below

DensityPlot[(E^-(x^2 +
y^2)^2)^2 + ((E^-(x^2 + y^2)^2) (x^2 + y^2) Cos[
2 Pi])^2, {x, -3, 3}, {y, -3, 3}, PlotTheme -> "Minimal",
PlotRange -> All, PlotPoints -> 50, ColorFunction -> "Rainbow"]



To create

I have then separated my plot into n number (50 for this code below) of grids and found the center of each grid with the code (from this answer):

means[n_] := MovingAverage[Subdivide[##, n] & @@ #, 2] &

centers[{nc_, nr_}, {xrange_, yrange_}] :=
Tuples[{means[nc]@xrange, means[nr]@yrange}]

{xrange, yrange} = {{-3, 3}, {-3, 3}};

{nc, nr} = {50, 50};

centers[{nc, nr}, {xrange, yrange}]



If I plot my image using my grids and center points I get

My problem is that I would like to only get the center points of the grids that cover the circular shape.

My attempt

I have tried to initiate some kind of if loop that would be able to only pick out the corresponding co ordinates that are on the circular image from the second piece of the code (reposted below again). However I haven't been able to actually come up with a logical condition for this.

means[n_] := MovingAverage[Subdivide[##, n] & @@ #, 2] &

centers[{nc_, nr_}, {xrange_, yrange_}] :=
Tuples[{means[nc]@xrange, means[nr]@yrange}]

{xrange, yrange} = {{-3, 3}, {-3, 3}};

{nc, nr} = {50, 50};

centers[{nc, nr}, {xrange, yrange}]



Thank you for your help

dp = DensityPlot[(E^-(x^2 + y^2)^2)^2 + ((E^-(x^2 + y^2)^2) (x^2 +
y^2) Cos[2 Pi])^2, {x, -3, 3}, {y, -3, 3},
PlotTheme -> "Minimal", PlotRange -> All, PlotPoints -> 50,
ColorFunction -> "Rainbow"];


Modify the function centers to select points that lie within a specified region:

ClearAll[centers2]
centers2[region_: Disk[{0, 0}, 1]][{nc_, nr_}, {xrange_, yrange_}] :=
Select[RegionMember[region]]@centers[{nc, nr}, {xrange, yrange}]


Examples:

{xrange, yrange} = {{-3, 3}, {-3, 3}};

{nc, nr} = {50, 50};

Show[dp, Graphics[{White, PointSize[Medium], Circle[],
Point @ centers2[][{nc, nr}, {xrange, yrange}]}]]


radius = 1.3;

Show[dp, Graphics[{White, PointSize[Medium], Circle[{0, 0}, radius],
Point @ centers2[Disk[{0,0}, radius]][{nc, nr}, {xrange, yrange}]}]]


SeedRandom[1]
rp = RandomReal[{-3, 3}, {15, 2}];
region = Polygon[rp[[Last@FindShortestTour@rp]]];

Show[dp, Graphics[{White, PointSize[Medium], FaceForm[],
EdgeForm[White], region,
Point @ centers2[region][{nc, nr}, {xrange, yrange}]}]]


• Thank you so much! But how will I now get the co ordinates of the points that are displayed? Jun 2, 2021 at 7:47
• @PracticalFruit, centers2[Disk[{0,0}, radius]][{nc, nr}, {xrange, yrange}] gives the coordinates.
– kglr
Jun 2, 2021 at 8:22
• Thank you very much! Jun 2, 2021 at 8:41
• Hi, for some reason, when I input the code you have above I get the plot with no white dots for some reason. Can you maybe think why? Jun 4, 2021 at 4:56