MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: point in convex hull


steve fisk wrote:
> If pts is a set of points, and w is a point I can use ConvexHull[pts] to 
> find the convex hull of the points in pts. Is there a function to 
> determine if w lies in the convex hull?
> 
If you integrate 1/(x-w) along the boundary of the convex hull you get
2Pi*I if w lies inside, 0 else.

Off[NIntegrate::ploss, General::spell1];
inConvexHull[pt_, set_, tol_:10^(-3)] := Module[{path, x},
 path = Prepend[
   Complex @@@ set[[(Append[#1, First[#1]] & )[ConvexHull[set]]]], x];
 Abs[NIntegrate[1/(x - Complex @@ pt), Evaluate[path]] - 2*Pi*I] < tol]

data = Table[Random[], {10}, {2}];

inConvexHull[{1/2, 1/2}, data]
==>
True

inConvexHull[{1/2, -1/2}, data]
==>
False

-- 
Peter Pein
Berlin


  • Prev by Date: Re: point in convex hull
  • Next by Date: Upgrading to v5.1?
  • Previous by thread: Re: Re: point in convex hull
  • Next by thread: Re: point in convex hull