[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Polygon hull



Barbara A Cohen (bcohen@lpl.arizona.edu) writes:

> Hi, I have an array of data and I want to plot a polygon that encompasses
> all the points within it.  I have tried JHU's convexhull but it fails to
> encompass all the data (example below).  Does anyone else have a program
> to do this? 

You can find the convex hull with the Triangulate command, like
this:

   x=[0.36,0.35,0.39,0.42,0.60,0.41,0.48,0.73,0.46,0.42,0.42,0.42, $
      0.47,0.44,0.47,0.49,0.54,0.64,0.65]
   y=[0.19,0.26,0.26,0.26,0.14,0.22,0.15,0.10,0.16,0.30,0.27,0.27, $
      0.23,0.23,0.22,0.16,0.16,0.08,0.08]
   TVLCT, [255, 255, 100], [0, 255, 100], [0, 0, 100], 1
   Device, Decomposed=0
   Plot, x, y, color=2, /nodata, background=3
   Triangulate, x, y, triangles, hull
   Plots, [x[hull],x[hull[0]]], [y[hull],y[hull[0]]], Color=1
   Plots, x, y, psym=4, Color=2

Cheers,

P.S. I can't tell whether "encompass" means that the
points can't exist on the perimeter line. I still can't
ftp to the JHU site with a browser. I don't know why. :-(

David

-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155