# How to check if points lie within a circle

So we have two graphs overlapping with the Show[] function, one is a network of connected points, and the other displays three circles over the top of the points. I'm trying to check which points lie within the circles, and put them into separate lists. I first tried to use the distance equation, checking if the distances from the nodes to the centre of the circle is less than the radius:

   For[m = 1, m <= Length[coordinates],
nodex = Part[Part[coordinates, m], 1];
nodey = Part[Part[coordinates, m], 2];
circlecheck1 =
distanceFunction[Part[circle1Centre, 1], nodex,
Part[circle1Centre, 2], nodey];
AppendTo[inCircle1, {nodex, nodey}]]; m = m + 1]


(Note that all of the functions and Part[] variables function just fine in other parts of the code, so I'm certain this is not the issue.)

However, I ran into a problem: since we're using the Show[] function, it seems that the two "graphs" have different axes size, and so my assumption that they will lie on the same axis and obey the distance function is wrong.

Is there a way to either check whether the circles overlap anyway, or to force the axes to share the same length?

• You should try to include a minimal working example with just enough code that someone can reproduce your problem. Once enough info is present you'll get much better feedback, otherwise it'll just be speculation about what might be going wrong. Apr 28, 2022 at 12:36
• What is the relation between the circles in 2D graphics space and the vertices of your graph? A graph is not a graphics primitive see image.
– Syed
Apr 28, 2022 at 15:54

You can pick points within a tolerance with Disk, that is a circular region including its inside. MemberQ generates a function which checks if coordinate is in the region, Select chooses those points which fulfil this requirement. By applying the list of selector functions to your list of random points you can get separate lists of matched points per circle:

With[{pts = RandomReal[{-10, 10}, {10000, 2}],
disks = Table[Disk[RandomReal[{-5, 5}, 2], RandomReal[{1, 2}]], {3}]},
Show[ListPlot[(Select@RegionMember@#)[pts] & /@ disks],
Graphics[RegionBoundary /@ disks, PlotRange -> Full],
AspectRatio -> Automatic]]


• I'm a little confused about this answer; are you plotting points directly into the discs or are you plotting points and eliminating any that lie outwith the discs? Apr 28, 2022 at 14:15
• Okay, the selection method is so concise that it might be a bit hard to understand. I'm selecting from random points distributed over a much larger rectangle, and only those points which correspond each Disk region get selected in each group (coloured differently). So, there's elimination, I was a bit cheap on not plotting the background... Apr 28, 2022 at 14:23

You have a circle and a set of points

disk = Graphics[Disk[{0, 0}, 2]];
pts = RandomReal[{-3, 3}, {10, 2}]
ptsplot = Graphics[{PointSize[Large], Red, Point[pts]}];


We can plot the for inspection and illustrational purposes

Show[disk, ptsplot]


And a True or False statement for each of the previously considered points:

Table[Element[pts[[i]], Disk[{0, 0}, 2]], {i, 1, Length@pts}]


We can, also, count how many of said points lie inside the circle with the following command:

Length@Select[
Table[Element[pts[[i]], Disk[{0, 0}, 2]], {i, 1, Length@pts}], # ==
True &]


Finally, I am assuming that you want to know which ones are inside the circle. More precisely, getting the position of the points from the initial list that contains all of them. We can use the previously obtained Boolean True and False list to extract the positions of the True elements like so:

pos = Position[
Table[Element[pts[[i]], Disk[{0, 0}, 2]], {i, 1,
Length@pts}], _?(# == True &)]


Finally, I assume that you might, also, want the points themselves in an automatic way. You can use the previous output to Extract them:

Extract[pts, pos]