1
$\begingroup$

Here I have a list of points on the plane:

lst = RandomReal[{-5, 5}, {55, 2}];

and a disk with the radius r=1 drawn around the point number i. i will be taken equal 5 in this example below.

I want to select all points with the distance to the disk larger than r. Here I am doing it:

    Clear[lst2, lst3, i, r];
i = 5;
r = 1;

(* This makes a list with a dropped i-th element *)
lstA = lst /. x_ /; x == lst[[i]] -> Nothing;

(* This selects a sublist from the lstA that fulfills the requirement *)

lst1 = Select[lstA, RegionDistance[Disk[lst[[i]], 1], #] >= 2 r &];

For the visual purpose here is a list of points that are closer than 1 to the disk:

lst2 = Select[lstA, RegionDistance[Disk[lst[[i]], 1], #] < 2 r &];

Now let us draw this, showing the points that must be closer in red, and those far - in black:

    Graphics[{Blue, Opacity[0.3], Disk[lst[[i]], 1], Opacity[1], Black, 
  Point[#] & /@ lst1, Red, Point[#] & /@ lst2}]

enter image description here

We see something quite unexpected. Some red points are outside it, though must be inside. Do I strongly miss something?

$\endgroup$
  • $\begingroup$ The red dots do not have to be inside: they can be outside as long as the distance to the closest point in the disk is less than r. From the docs of RegionDistance: "Region distance is effectively given by MinValue[{Norm[p-q],q\[Element]reg},q]." $\endgroup$ – Marius Ladegård Meyer Jan 18 '17 at 14:54
3
$\begingroup$

You forgot to put the correct origin in the Disk plot. And the distance should be smaler or equal otherwise you dont get point inside (with distance equal to zero).

lst = RandomReal[{-5, 5}, {55, 2}];
Clear[lst1, lst2, i, r];
i = 5;
r = 0;

lst1 = Select[lst, RegionDistance[Disk[lst[[3]], 1], #] >= r &];

lst2 = Select[lst, RegionDistance[Disk[lst[[3]], 1], #] <= r &];

 Graphics[{Blue, Opacity[0.3], Disk[lst[[3]], 1], Opacity[1], Black, Point[#] & /@ lst1, Red, Point[#] & /@ lst2}]

enter image description here

$\endgroup$
  • $\begingroup$ You are right. I tried to remove the question, but failed $\endgroup$ – Alexei Boulbitch Jan 18 '17 at 17:57
3
$\begingroup$

I think RegionMember is what you are looking for.

lst = RandomReal[{-5, 5}, {55, 2}];

i = 5;
r = 1;

regionDisk = Disk[lst[[i]], 1];

and then

lst2 = Select[lst, RegionMember[regionDisk, #] &]

Graphics[{
  Blue,
  Opacity[0.3],
  regionDisk,
  Opacity[1],
  Black,
  Point[lst],
  Red,
  Point[lst2]
  }]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.