Skip to main content
added 242 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Update: As noted by Henrik and Rahul the original answer is not the correct approach. An alternative method that gives the correct polygon containing redPt is based on using Graphics`PolygonUtils`InPolygonQ:

polygons = MeshPrimitives[plot1ClearAll[f]
f[r_, 2];
polyp_] := Pick[polygons Pick[#, Graphics`PolygonUtils`InPolygonQ[#, redPt]p] & /@ polygons];#] &@
   MeshPrimitives[r, 2];

Show[plot1, 
 Graphics[{PointSize[Large], Point@redPt, Opacity[.5, Red], poly f[plot1, redPt]}]] 

enter image description here

To get the coordinates, use

poly[[1f[plot1, redPt][[1, 1]]

{{0.67033, 0.84245}, {0.620283, 0.648944}, {0.829905, 0.700287}}

OriginalUsing Henrik's example (incorrectR) answer:

Show[R, Graphics[{PointSize[Large], Point@redPt, Opacity[.5, Red],  f[R, redPt]}]]

enter image description here

Original (incorrect) answer:

Nearest[MeshCoordinates[plot1], redPts, 3]

Update: As noted by Henrik and Rahul the original answer is not the correct approach. An alternative method that gives the correct polygon containing redPt is based on using Graphics`PolygonUtils`InPolygonQ:

polygons = MeshPrimitives[plot1, 2];
poly = Pick[polygons, Graphics`PolygonUtils`InPolygonQ[#, redPt] & /@ polygons];
Show[plot1, 
 Graphics[{PointSize[Large], Point@redPt, Opacity[.5, Red], poly}]]

enter image description here

To get the coordinates, use

poly[[1, 1]]

{{0.67033, 0.84245}, {0.620283, 0.648944}, {0.829905, 0.700287}}

Original (incorrect) answer:

 Nearest[MeshCoordinates[plot1], redPts, 3]

Update: As noted by Henrik and Rahul the original answer is not the correct approach. An alternative method that gives the correct polygon containing redPt is based on using Graphics`PolygonUtils`InPolygonQ:

ClearAll[f]
f[r_, p_] :=  Pick[#, Graphics`PolygonUtils`InPolygonQ[#, p] & /@ #] &@
   MeshPrimitives[r, 2];

Show[plot1, 
 Graphics[{PointSize[Large], Point@redPt, Opacity[.5, Red],  f[plot1, redPt]}]] 

enter image description here

To get the coordinates, use

f[plot1, redPt][[1, 1]]

{{0.67033, 0.84245}, {0.620283, 0.648944}, {0.829905, 0.700287}}

Using Henrik's example (R):

Show[R, Graphics[{PointSize[Large], Point@redPt, Opacity[.5, Red],  f[R, redPt]}]]

enter image description here

Original (incorrect) answer:

Nearest[MeshCoordinates[plot1], redPts, 3]
added 645 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Update: As noted by Henrik and Rahul the original answer is not the correct approach. An alternative method that gives the correct polygon containing redPt is based on using Graphics`PolygonUtils`InPolygonQ:

polygons = MeshPrimitives[plot1, 2];
poly = Pick[polygons, Graphics`PolygonUtils`InPolygonQ[#, redPt] & /@ polygons];
Show[plot1, 
 Graphics[{PointSize[Large], Point@redPt, Opacity[.5, Red], poly}]]

enter image description here

To get the coordinates, use

poly[[1, 1]]

{{0.67033, 0.84245}, {0.620283, 0.648944}, {0.829905, 0.700287}}

Original (incorrect) answer:

 Nearest[MeshCoordinates[plot1], redPts, 3]
 Nearest[MeshCoordinates[plot1], redPts, 3]

Update: As noted by Henrik and Rahul the original answer is not the correct approach. An alternative method that gives the correct polygon containing redPt is based on using Graphics`PolygonUtils`InPolygonQ:

polygons = MeshPrimitives[plot1, 2];
poly = Pick[polygons, Graphics`PolygonUtils`InPolygonQ[#, redPt] & /@ polygons];
Show[plot1, 
 Graphics[{PointSize[Large], Point@redPt, Opacity[.5, Red], poly}]]

enter image description here

To get the coordinates, use

poly[[1, 1]]

{{0.67033, 0.84245}, {0.620283, 0.648944}, {0.829905, 0.700287}}

Original (incorrect) answer:

 Nearest[MeshCoordinates[plot1], redPts, 3]
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

 Nearest[MeshCoordinates[plot1], redPts, 3]