2
$\begingroup$

I have a list of points which form a closed (connected) contour or path in two dimensions. I would like to get all points from a second list which satisfy the requirement that they are inside the contour. Of course, I could implement this, but I think that it would be quite tedious. Is there a dedicated Mathematica function or a quick solution which can do it?

The lists are Mathematica tables of tables of two elements representing the Cartesian coordinates of the points. As test examples for the lists you may use.

listcontour={{-1,0},{-1.5,0.5},{0.0,1},{1,0},{-1,0}};
list={{-2,3},{-0.5,0.5},{0.2,0.1}}

I would want the routine to return a list of indices of these points, in this case {2,3}. These are just examples, of course.

$\endgroup$
3
  • 2
    $\begingroup$ Could you pleas provide Mathematica code to produce the points and the contour, so that we don't have to guess how each of them is to be specified (contour as a parametric function, or as image or list of points, or...?) I'd suggest starting with ?Region* $\endgroup$
    – Jens
    Commented May 6, 2016 at 14:55
  • $\begingroup$ There is the InterpolatingPolynomial function. An example how it works you can find here: Get polynomial interpolation formula. $\endgroup$
    – Artes
    Commented May 6, 2016 at 14:58
  • $\begingroup$ Since you have a list of points, you can make a ParametricRegion out of it and then use RegionMember. $\endgroup$
    – BlacKow
    Commented May 6, 2016 at 14:59

2 Answers 2

4
$\begingroup$

Use BoundaryDiscretizeGraphics, RegionDifference, Select, and MemberQ

points1 = CirclePoints[3, 40];
points2 = CirclePoints[1, 40];
{region1, region2} = 
 BoundaryDiscretizeGraphics@*ListCurvePathPlot /@ {points1, points2}
region3 = RegionDifference[region1, region2]
Show[
 RegionPlot@region3,
 Select[RandomReal[{-5, 5}, {1000, 2}], RegionMember[region3]] // 
  ListPlot
 ]

enter image description here

$\endgroup$
2
  • $\begingroup$ Looks good. A slight problem I am having is that it does not tell me the indexes of the elements (or alternatively it would need to work with sub-tables that have more then the first 2 positional elements). The obvious approach to search the elements of the table of the successful candidates in the original table would be pretty inactive for the large number of points I am dealing with. $\endgroup$
    – highsciguy
    Commented May 6, 2016 at 17:24
  • $\begingroup$ @highsciguy Your original post was pretty sparse on details, so I had to guess what you wanted. The basic point here is to create a region from your list of points, I used BoundaryDiscretizeGraphics to do this. Next you use Select in combination with RegionMember to pick the elements of the second list in that region. Whether you want the elements themselves or the indexes is trivial, a small change you could make $\endgroup$
    – Jason B.
    Commented May 6, 2016 at 18:39
0
$\begingroup$

If you have a function that generated the contour and you know the contour value, then you could just evaluate the function at each point in the second list and know whether the each point is in the contour, on the contour, or outside the contour. (I'm not try to be facetious. It's just that sometimes I don't always see the forest for the trees.)

Alternatively, you could go the "point-in-polygon" approach.

$\endgroup$

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